ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-09-07 04:59:20
Exec Total Coverage
Lines: 1991 4584 43.4%
Functions: 127 337 37.7%
Branches: 1345 3782 35.6%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro/inline/draw.inl"
6 #include "allegro5/joystick.h"
7 #include "base/files.h"
8 #include "base/render.h"
9 #include "base/zdefs.h"
10 #include "zalleg/zalleg.h"
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include <functional>
14 #include <queue>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <cstring>
18 #include <math.h>
19 #include <map>
20 #include <filesystem>
21 #include <ctype.h>
22 #include <sstream>
23 #include "base/version.h"
24 #include "base/zc_alleg.h"
25 #include "gamedata.h"
26 #include "zc/frame_timings.h"
27 #include "zc/replay_upload.h"
28 #include "zc/zc_init.h"
29 #include "init.h"
30 #include "zc/replay.h"
31 #include "zc/cheats.h"
32 #include "zc/render.h"
33 #include "base/zc_math.h"
34 #include "base/zapp.h"
35 #include "dialog/cheatkeys.h"
36 #include "metadata/metadata.h"
37 #include "zc/zelda.h"
38 #include "zc/saves.h"
39 #include "tiles.h"
40 #include "base/colors.h"
41 #include "pal.h"
42 #include "base/zsys.h"
43 #include "base/qst.h"
44 #include "zc/zc_sys.h"
45 #include "play_midi.h"
46 #include "gui/jwin_a5.h"
47 #include "base/jwinfsel.h"
48 #include "base/gui.h"
49 #include "midi.h"
50 #include "subscr.h"
51 #include "zc/maps.h"
52 #include "sprite.h"
53 #include "zc/guys.h"
54 #include "zc/hero.h"
55 #include "zc/title.h"
56 #include "particles.h"
57 #include "sound/zcmusic.h"
58 #include "zc/ffscript.h"
59 #include "dialog/info.h"
60 #include "dialog/alert.h"
61 #include "zc/combos.h"
62 #include "zc/jit.h"
63 #include "zc/zc_subscr.h"
64 #include <fmt/format.h>
65 #include "zconsole/ConsoleLogger.h"
66 #include "zinfo.h"
67 #include "base/misctypes.h"
68 #include "music_playback.h"
69 #include "base/new_menu.h"
70 #include "base/files.h"
71 #include "iter.h"
72
73 #ifdef __EMSCRIPTEN__
74 #include "base/emscripten_utils.h"
75 #endif
76
77 using namespace std::chrono_literals;
78
79 extern bool Playing;
80 int32_t sfx_voice[WAV_COUNT];
81 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
82 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
83
84 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
85 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
86
87 extern byte monochrome_console;
88
89 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
90 extern std::string loadlast;
91 extern char *sfx_string[WAV_COUNT];
92 byte use_dwm_flush;
93 byte use_save_indicator;
94 int32_t paused_midi_pos = 0;
95 byte midi_suspended = 0;
96 byte zc_192b163_warp_compatibility;
97 bool epilepsyFlashReduction;
98 signed char pause_in_background_menu_init = 0;
99 byte pause_in_background = 0;
100 bool is_sys_pal = false;
101 static bool load_control_called_this_frame;
102 extern PALETTE* hw_palette;
103 extern bool update_hw_pal;
104 extern const char* dmaplist(int32_t index, int32_t* list_size);
105 int32_t getnumber(const char *prompt,int32_t initialval);
106
107 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
108 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
109
110 #ifdef ALLEGRO_LINUX
111 static const char *samplepath = "samplesoundset/patches.dat";
112 #endif
113 char qst_files_path[2048];
114
115 extern TopMenu the_player_menu;
116 #ifdef _MSC_VER
117 #define getcwd _getcwd
118 #endif
119
120 bool rF11();
121 bool rI();
122 bool rQ();
123 bool zc_key_pressed();
124
125 #ifdef _WIN32
126
127 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
128 extern "C"
129 {
130 typedef HRESULT(WINAPI *t_DwmFlush)();
131 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
132 }
133
134 void do_DwmFlush()
135 {
136 static HMODULE shell = LoadLibrary("dwmapi.dll");
137
138 if(!shell)
139 return;
140
141 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
142 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
143
144 BOOL enabled;
145 isEnabled(&enabled);
146
147 if(isEnabled)
148 flush();
149 }
150
151 #endif // _WIN32
152
153 314 void zc_exit(int code)
154 {
155 extern CConsoleLoggerEx zscript_coloured_console;
156
157 314 set_is_exiting();
158
159
1/2
✓ Branch 0 taken 314 times.
✗ Branch 1 not taken.
314 if (replay_get_mode() == ReplayMode::Record) replay_save();
160 314 replay_stop();
161 314 music_stop();
162 314 kill_sfx();
163
164
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 305 times.
314 if (get_qr(qr_OLD_SCRIPT_VOLUME))
165 {
166 //restore user volume settings
167
2/2
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 1 times.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
168 {
169 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
170 1 }
171
2/2
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 1 times.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
172 {
173 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
174 1 }
175
2/2
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 1 times.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
176 {
177 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
178 1 }
179
1/2
✓ Branch 0 taken 305 times.
✗ Branch 1 not taken.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
180 {
181 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
182 }
183 305 }
184
1/2
✓ Branch 0 taken 314 times.
✗ Branch 1 not taken.
314 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
185 {
186 pan_style = (int32_t)FFCore.usr_panstyle;
187 }
188 314 save_game_configs();
189
190 314 zscript_coloured_console.kill();
191 314 jit_shutdown();
192 314 frame_timings_end();
193 314 quit_game();
194
195 314 Z_message("ZQuest Classic website: https://zquestclassic.com\n");
196 314 Z_message("ZQuest Classic docs: https://docs.zquestclassic.com\n");
197
198 314 allegro_exit();
199 314 exit(code);
200 }
201
202 93594 bool flash_reduction_enabled(bool check_qr)
203 {
204
4/4
✓ Branch 0 taken 88914 times.
✓ Branch 1 taken 4680 times.
✓ Branch 2 taken 87624 times.
✓ Branch 3 taken 92304 times.
93594 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
205 }
206
207 // Dialogue largening
208 void large_dialog(DIALOG *d)
209 {
210 large_dialog(d, 1.5);
211 }
212
213 void large_dialog(DIALOG *d, float RESIZE_AMT)
214 {
215 if(!d[0].d1)
216 {
217 d[0].d1 = 1;
218 int32_t oldwidth = d[0].w;
219 int32_t oldheight = d[0].h;
220 int32_t oldx = d[0].x;
221 int32_t oldy = d[0].y;
222 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
223 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
224 d[0].w = int32_t(d[0].w*RESIZE_AMT);
225 d[0].h = int32_t(d[0].h*RESIZE_AMT);
226
227 for(int32_t i=1; d[i].proc !=NULL; i++)
228 {
229 // Place elements horizontally
230 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
231 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
232
233 if(d[i].proc != d_stringloader)
234 {
235 if(d[i].proc==d_bitmap_proc)
236 {
237 d[i].w *= 2;
238 }
239 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
240 }
241
242 // Place elements vertically
243 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
244 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
245
246 // Vertically resize elements
247 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
248 {
249 d[i].h = int32_t((double)d[i].h*1.5);
250 }
251 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
252 {
253 d[i].y += int32_t((double)d[i].h*0.25);
254 d[i].h = int32_t((double)d[i].h*1.25);
255 }
256 else if(d[i].proc==d_bitmap_proc)
257 {
258 d[i].h *= 2;
259 }
260 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
261
262 // Fix frames
263 if(d[i].proc == jwin_frame_proc)
264 {
265 d[i].x++;
266 d[i].y++;
267 d[i].w-=4;
268 d[i].h-=4;
269 }
270 }
271 }
272
273 for(int32_t i=1; d[i].proc!=NULL; i++)
274 {
275 if(d[i].proc==jwin_slider_proc)
276 continue;
277
278 // Bigger font
279 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
280
281 if(!d[i].dp2 && bigfontproc)
282 {
283 d[i].dp2 = get_zc_font(font_lfont_l);
284 }
285 else if(!bigfontproc)
286 {
287 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
288 }
289
290 // Make checkboxes work
291 if(d[i].proc == jwin_check_proc)
292 d[i].proc = jwin_checkfont_proc;
293 else if(d[i].proc == jwin_radio_proc)
294 d[i].proc = jwin_radiofont_proc;
295 }
296
297 jwin_center_dialog(d);
298 }
299
300 static char cfg_sect[] = "zeldadx"; //We need to rename this.
301 static char ctrl_sect[] = "Controls";
302 static char sfx_sect[] = "Volume";
303
304 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
305 {
306 return D_O_K;
307 }
308
309 bool is_reserved_key(int c)
310 {
311 switch(c)
312 {
313 case KEY_ESC:
314 return true;
315 }
316 return false;
317 }
318 bool is_reserved_keycombo(int c, int modflag)
319 {
320 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
321 return true;
322 return false;
323 }
324 bool checkcheat(Cheat cheat)
325 {
326 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
327 return true; //Main key pressed
328 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
329 return true; //Alt key pressed
330 return false;
331 }
332 314 void load_default_cheatkeys()
333 {
334 314 memset(cheatkeys, 0, sizeof(cheatkeys));
335 314 cheatkeys[Cheat::Life][0] = KEY_H;
336 314 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
337 314 cheatkeys[Cheat::Magic][0] = KEY_M;
338 314 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
339 314 cheatkeys[Cheat::Rupies][0] = KEY_R;
340 314 cheatkeys[Cheat::Bombs][0] = KEY_B;
341 314 cheatkeys[Cheat::Arrows][0] = KEY_A;
342 314 cheatkeys[Cheat::Clock][0] = KEY_I;
343 314 cheatkeys[Cheat::Walls][0] = KEY_F11;
344 314 cheatkeys[Cheat::Fast][0] = KEY_Q;
345 314 cheatkeys[Cheat::Light][0] = KEY_L;
346 314 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
347 314 cheatkeys[Cheat::Kill][0] = KEY_K;
348 314 cheatkeys[Cheat::GoTo][0] = KEY_G;
349 314 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
350 314 cheatkeys[Cheat::ShowL0][0] = KEY_0;
351 314 cheatkeys[Cheat::ShowL1][0] = KEY_1;
352 314 cheatkeys[Cheat::ShowL2][0] = KEY_2;
353 314 cheatkeys[Cheat::ShowL3][0] = KEY_3;
354 314 cheatkeys[Cheat::ShowL4][0] = KEY_4;
355 314 cheatkeys[Cheat::ShowL5][0] = KEY_5;
356 314 cheatkeys[Cheat::ShowL6][0] = KEY_6;
357 314 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
358 314 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
359 314 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
360 314 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
361 314 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
362 314 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
363 314 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
364 314 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
365 314 }
366
367 static bool loaded_game_configs;
368
369 314 void load_game_configs()
370 {
371 314 loaded_game_configs = true;
372 314 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
373 314 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
374 314 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
375 314 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
376 314 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
377 314 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
378 314 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
379 314 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
380 314 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
381 314 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
382 314 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
383 314 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
384 314 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
385 314 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
386
387 //cheat modifier keya
388 314 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
389 314 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
390 314 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
391 314 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
392
393 //cheat keys
394 314 load_default_cheatkeys();
395 char buf[256];
396
2/2
✓ Branch 0 taken 314 times.
✓ Branch 1 taken 11304 times.
11618 for(size_t q = 1; q < Cheat::Last; ++q)
397 {
398
1/2
✓ Branch 0 taken 11304 times.
✗ Branch 1 not taken.
11304 if(!bindable_cheat((Cheat)q)) continue;
399 11304 std::string cheatname = cheat_to_string((Cheat)q);
400
1/2
✓ Branch 0 taken 11304 times.
✗ Branch 1 not taken.
11304 util::lowerstr(cheatname);
401 11304 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
402
1/2
✓ Branch 0 taken 11304 times.
✗ Branch 1 not taken.
11304 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
403 11304 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
404
1/2
✓ Branch 0 taken 11304 times.
✗ Branch 1 not taken.
11304 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
405 11304 }
406
407
1/2
✓ Branch 0 taken 314 times.
✗ Branch 1 not taken.
314 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
408 joystick_index = 0;
409
410 314 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
411 314 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
412 314 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
413 314 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
414 314 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
415 314 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
416 314 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
417 314 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
418 314 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
419 314 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
420
421 314 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
422 314 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
423 314 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
424 314 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
425
426 314 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
427 314 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
428 314 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
429 314 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
430 314 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
431 314 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
432 314 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
433 314 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
434 314 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
435 314 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
436 314 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
437
438 314 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
439 314 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
440 314 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
441 314 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
442
443 314 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
444
445 314 midi_volume = zc_get_config(sfx_sect,"midi",255);
446 314 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
447 314 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
448 314 pan_style = zc_get_config(sfx_sect,"pan",1);
449 314 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
450 314 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
451 314 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
452 314 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
453 314 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
454 314 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
455 314 ShowBottomPixels = zc_get_config(cfg_sect,"bottom_8_px",0);
456 314 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
457 314 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
458 #ifdef __EMSCRIPTEN__
459 if (em_is_mobile()) NameEntryMode = 2;
460 #endif
461 314 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
462 314 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
463 314 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
464 314 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
465 314 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
466 314 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
467
468 314 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
469 314 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
470 314 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
471 314 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
472 314 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
473 314 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
474 314 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
475
476 314 loadlast = zc_get_config(cfg_sect,"load_last_path","");
477
478 314 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
479
480 314 info_opacity = zc_get_config("zc","debug_info_opacity",255);
481 #ifdef _WIN32
482 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
483 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
484 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
485
486 // This one's for Aero
487 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
488
489 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
490 #else //UNIX
491 314 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
492 314 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
493 #endif
494 314 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
495 314 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
496
497 314 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
498 314 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
499 314 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
500 314 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
501 314 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
502 314 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
503 314 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
504 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
505 314 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
506 314 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
507 314 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
508 314 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
509 314 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
510 314 }
511
512 void save_control_configs(bool kb)
513 {
514 if(kb)
515 {
516 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
517 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
518 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
519 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
520
521 if (!replay_is_replaying())
522 {
523 zc_set_config(ctrl_sect,"key_a",Akey);
524 zc_set_config(ctrl_sect,"key_b",Bkey);
525 zc_set_config(ctrl_sect,"key_s",Skey);
526 zc_set_config(ctrl_sect,"key_l",Lkey);
527 zc_set_config(ctrl_sect,"key_r",Rkey);
528 zc_set_config(ctrl_sect,"key_p",Pkey);
529 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
530 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
531 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
532 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
533 zc_set_config(ctrl_sect,"key_up", DUkey);
534 zc_set_config(ctrl_sect,"key_down", DDkey);
535 zc_set_config(ctrl_sect,"key_left", DLkey);
536 zc_set_config(ctrl_sect,"key_right",DRkey);
537 }
538 }
539 else
540 {
541 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
542 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
543 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
544 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
545 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
546 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
547 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
548 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
549 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
550 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
551 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
552 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
553 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
554 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
555
556 zc_set_config(ctrl_sect,"btn_a",Abtn);
557 zc_set_config(ctrl_sect,"btn_b",Bbtn);
558 zc_set_config(ctrl_sect,"btn_s",Sbtn);
559 zc_set_config(ctrl_sect,"btn_m",Mbtn);
560 zc_set_config(ctrl_sect,"btn_l",Lbtn);
561 zc_set_config(ctrl_sect,"btn_r",Rbtn);
562 zc_set_config(ctrl_sect,"btn_p",Pbtn);
563 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
564 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
565 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
566 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
567
568 zc_set_config(ctrl_sect,"btn_up",DUbtn);
569 zc_set_config(ctrl_sect,"btn_down",DDbtn);
570 zc_set_config(ctrl_sect,"btn_left",DLbtn);
571 zc_set_config(ctrl_sect,"btn_right",DRbtn);
572 }
573 }
574
575 void save_cheatkeys()
576 {
577 char buf[256];
578 for(size_t q = 1; q < Cheat::Last; ++q)
579 {
580 if(!bindable_cheat((Cheat)q)) continue;
581 std::string cheatname = cheat_to_string((Cheat)q);
582 util::lowerstr(cheatname);
583 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
584 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
585 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
586 if(cheatkeys[q][1])
587 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
588 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
589 }
590 }
591
592 314 void save_game_configs()
593 {
594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 314 times.
314 if (!loaded_game_configs) return;
595
596 314 packfile_password("");
597
598
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 314 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
314 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
599 {
600 int o_window_x, o_window_y;
601 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
602 zc_set_config(cfg_sect,"window_x",o_window_x);
603 zc_set_config(cfg_sect,"window_y",o_window_y);
604 }
605
606
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 314 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
314 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
607 {
608 window_width = al_get_display_width(all_get_display());
609 window_height = al_get_display_height(all_get_display());
610 zc_set_config(cfg_sect,"window_width",window_width);
611 zc_set_config(cfg_sect,"window_height",window_height);
612 }
613
614 314 zc_set_config(cfg_sect,"load_last_path",loadlast.c_str());
615 314 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
616
617 314 flush_config_file();
618 #ifdef __EMSCRIPTEN__
619 em_sync_fs();
620 #endif
621 314 }
622
623 //----------------------------------------------------------------
624
625 // Timers
626
627 38588 void fps_callback()
628 {
629 38588 lastfps=framecnt;
630 38588 framecnt=0;
631 38588 }
632
633 END_OF_FUNCTION(fps_callback)
634
635 314 int32_t Z_init_timers()
636 {
637 static bool didit = false;
638 const static char *err_str = "Couldn't allocate timer";
639 314 err_str = err_str; //Unused variable warning
640
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 314 times.
314 if(didit)
642 return 1;
643
644 314 didit = true;
645
646 LOCK_VARIABLE(lastfps);
647 LOCK_VARIABLE(framecnt);
648 LOCK_FUNCTION(fps_callback);
649
650
1/2
✓ Branch 0 taken 314 times.
✗ Branch 1 not taken.
314 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
651 return 0;
652
653 314 return 1;
654 314 }
655
656 314 void Z_remove_timers()
657 {
658 314 remove_int(fps_callback);
659 314 }
660
661 //----------------------------------------------------------------
662
663 void go()
664 {
665 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
666 }
667
668 void comeback()
669 {
670 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
671 }
672
673 void dump_pal(BITMAP *dest)
674 {
675 for(int32_t i=0; i<256; i++)
676 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
677 }
678
679 //----------------------------------------------------------------
680
681 int game_mouse_index = ZCM_BLANK;
682 static bool system_mouse = false;
683 92 bool sys_mouse()
684 {
685 92 system_mouse = true;
686 92 return MouseSprite::set(ZCM_NORMAL);
687 }
688 1628 bool game_mouse()
689 {
690 1628 system_mouse = false;
691 1628 return MouseSprite::set(game_mouse_index);
692 }
693 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
694 {
695 if(!bmp)
696 return;
697 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
698 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
699 if(bmp->w == scaledw && bmp->h == scaledh)
700 user_scale = false;
701 if(user_scale || sys_recolor)
702 {
703 if(!user_scale) scale = 1;
704 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
705 if(user_scale)
706 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
707 else
708 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
709 if(sys_recolor)
710 recolor_mouse(tmpbmp);
711 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
712 destroy_bitmap(tmpbmp);
713 }
714 else
715 {
716 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
717 }
718 }
719
720 //Handles converting the mouse sprite from the .dat file
721 void recolor_mouse(BITMAP* bmp)
722 {
723 for(int32_t x = 0; x < bmp->w; ++x)
724 {
725 for(int32_t y = 0; y < bmp->h; ++y)
726 {
727 int32_t color = getpixel(bmp, x, y);
728 switch(color)
729 {
730 case dvc(1):
731 color = jwin_pal[jcCURSORMISC];
732 break;
733 case dvc(2):
734 color = jwin_pal[jcCURSOROUTLINE];
735 break;
736 case dvc(3):
737 color = jwin_pal[jcCURSORLIGHT];
738 break;
739 case dvc(5):
740 color = jwin_pal[jcCURSORDARK];
741 break;
742 default:
743 continue;
744 }
745 putpixel(bmp, x, y, color);
746 }
747 }
748 }
749 void load_mouse()
750 {
751 PALETTE pal;
752 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
753 if (!cursor_bitmap)
754 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
755
756 enter_sys_pal();
757 MouseSprite::set(-1);
758 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
759 int32_t sz = 16*scale;
760 for(int32_t j = 0; j < 1; ++j)
761 {
762 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
763 if(zcmouse[j])
764 destroy_bitmap(zcmouse[j]);
765 zcmouse[j] = create_bitmap_ex(8,sz,sz);
766 clear_bitmap(zcmouse[j]);
767 clear_bitmap(tmpbmp);
768 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
769 recolor_mouse(tmpbmp);
770 if(sz!=16)
771 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
772 else
773 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
774 destroy_bitmap(tmpbmp);
775 }
776 if(!hw_palette) hw_palette = &RAMpal;
777 zc_set_palette(*hw_palette);
778
779 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
780 clear_bitmap(blankmouse);
781
782 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
783 MouseSprite::assign(ZCM_BLANK, blankmouse);
784 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
785
786 //Reload the mouse
787 if(system_mouse)
788 sys_mouse();
789 else game_mouse();
790
791 destroy_bitmap(blankmouse);
792 destroy_bitmap(cursor_bitmap);
793 exit_sys_pal();
794 }
795
796 // sets the video mode and initializes the palette and mouse sprite
797 314 bool game_vid_mode(int32_t mode,int32_t wait)
798 {
799
1/2
✓ Branch 0 taken 314 times.
✗ Branch 1 not taken.
314 if (is_headless())
800 314 return true;
801
802 extern int zq_screen_w, zq_screen_h;
803 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
804 {
805 return false;
806 }
807
808 scrx = (resx-320)>>1;
809 scry = (resy-240)>>1;
810 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
811 zcmouse[q] = NULL;
812 load_mouse();
813
814 for(int32_t i=240; i<256; i++)
815 RAMpal[i]=pal_gui[i];
816
817 zc_set_palette(RAMpal);
818 clear_to_color(screen,BLACK);
819
820 rest(wait);
821 return true;
822 314 }
823
824 322 void null_quest()
825 {
826
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 std::string title_assets_path = "modules/classic/title_gfx.dat";
827
2/4
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 322 times.
322 if (get_last_loaded_qstpath() == title_assets_path)
828 return;
829
830 byte skip_flags[4];
831
2/2
✓ Branch 0 taken 322 times.
✓ Branch 1 taken 8372 times.
8694 for (int i = 0; i < skip_max; i++)
832
1/2
✓ Branch 0 taken 8372 times.
✗ Branch 1 not taken.
8372 set_bit(skip_flags, i, 1);
833
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 set_bit(skip_flags, skip_tiles, 0);
834
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 set_bit(skip_flags, skip_csets, 0);
835
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
836
1/2
✓ Branch 0 taken 322 times.
✗ Branch 1 not taken.
322 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
837 322 sfxdat = 1;
838 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
839 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
840 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
841 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 322 times.
322 }
843
844 322 void init_NES_mode()
845 {
846 322 null_quest();
847 322 }
848
849 //----------------------------------------------------------------
850
851 qword trianglelines[16]=
852 {
853 0x0000000000000000ULL,
854 0xFD00000000000000ULL,
855 0xFDFD000000000000ULL,
856 0xFDFDFD0000000000ULL,
857 0xFDFDFDFD00000000ULL,
858 0xFDFDFDFDFD000000ULL,
859 0xFDFDFDFDFDFD0000ULL,
860 0xFDFDFDFDFDFDFD00ULL,
861 0xFDFDFDFDFDFDFDFDULL,
862 0x00FDFDFDFDFDFDFDULL,
863 0x0000FDFDFDFDFDFDULL,
864 0x000000FDFDFDFDFDULL,
865 0x00000000FDFDFDFDULL,
866 0x0000000000FDFDFDULL,
867 0x000000000000FDFDULL,
868 0x00000000000000FDULL,
869 };
870
871 word screen_triangles[29][32];
872
873 // the ULL suffixes are to prevent this warning:
874 // warning: integer constant is too large for "int32_t" type
875
876 qword triangles[4][16][8]= //[direction][value][line]
877 {
878 {
879 {
880 0x0000000000000000ULL,
881 0x0000000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL,
886 0x0000000000000000ULL,
887 0x0000000000000000ULL
888 },
889 {
890 0xFD00000000000000ULL,
891 0x0000000000000000ULL,
892 0x0000000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL,
896 0x0000000000000000ULL,
897 0x0000000000000000ULL
898 },
899 {
900 0xFDFD000000000000ULL,
901 0xFD00000000000000ULL,
902 0x0000000000000000ULL,
903 0x0000000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL,
906 0x0000000000000000ULL,
907 0x0000000000000000ULL
908 },
909 {
910 0xFDFDFD0000000000ULL,
911 0xFDFD000000000000ULL,
912 0xFD00000000000000ULL,
913 0x0000000000000000ULL,
914 0x0000000000000000ULL,
915 0x0000000000000000ULL,
916 0x0000000000000000ULL,
917 0x0000000000000000ULL
918 },
919 {
920 0xFDFDFDFD00000000ULL,
921 0xFDFDFD0000000000ULL,
922 0xFDFD000000000000ULL,
923 0xFD00000000000000ULL,
924 0x0000000000000000ULL,
925 0x0000000000000000ULL,
926 0x0000000000000000ULL,
927 0x0000000000000000ULL
928 },
929 {
930 0xFDFDFDFDFD000000ULL,
931 0xFDFDFDFD00000000ULL,
932 0xFDFDFD0000000000ULL,
933 0xFDFD000000000000ULL,
934 0xFD00000000000000ULL,
935 0x0000000000000000ULL,
936 0x0000000000000000ULL,
937 0x0000000000000000ULL
938 },
939 {
940 0xFDFDFDFDFDFD0000ULL,
941 0xFDFDFDFDFD000000ULL,
942 0xFDFDFDFD00000000ULL,
943 0xFDFDFD0000000000ULL,
944 0xFDFD000000000000ULL,
945 0xFD00000000000000ULL,
946 0x0000000000000000ULL,
947 0x0000000000000000ULL
948 },
949 {
950 0xFDFDFDFDFDFDFD00ULL,
951 0xFDFDFDFDFDFD0000ULL,
952 0xFDFDFDFDFD000000ULL,
953 0xFDFDFDFD00000000ULL,
954 0xFDFDFD0000000000ULL,
955 0xFDFD000000000000ULL,
956 0xFD00000000000000ULL,
957 0x0000000000000000ULL
958 },
959 {
960 0xFDFDFDFDFDFDFDFDULL,
961 0xFDFDFDFDFDFDFD00ULL,
962 0xFDFDFDFDFDFD0000ULL,
963 0xFDFDFDFDFD000000ULL,
964 0xFDFDFDFD00000000ULL,
965 0xFDFDFD0000000000ULL,
966 0xFDFD000000000000ULL,
967 0xFD00000000000000ULL
968 },
969 {
970 0xFDFDFDFDFDFDFDFDULL,
971 0xFDFDFDFDFDFDFDFDULL,
972 0xFDFDFDFDFDFDFD00ULL,
973 0xFDFDFDFDFDFD0000ULL,
974 0xFDFDFDFDFD000000ULL,
975 0xFDFDFDFD00000000ULL,
976 0xFDFDFD0000000000ULL,
977 0xFDFD000000000000ULL
978 },
979 {
980 0xFDFDFDFDFDFDFDFDULL,
981 0xFDFDFDFDFDFDFDFDULL,
982 0xFDFDFDFDFDFDFDFDULL,
983 0xFDFDFDFDFDFDFD00ULL,
984 0xFDFDFDFDFDFD0000ULL,
985 0xFDFDFDFDFD000000ULL,
986 0xFDFDFDFD00000000ULL,
987 0xFDFDFD0000000000ULL
988 },
989 {
990 0xFDFDFDFDFDFDFDFDULL,
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFDFDULL,
993 0xFDFDFDFDFDFDFDFDULL,
994 0xFDFDFDFDFDFDFD00ULL,
995 0xFDFDFDFDFDFD0000ULL,
996 0xFDFDFDFDFD000000ULL,
997 0xFDFDFDFD00000000ULL
998 },
999 {
1000 0xFDFDFDFDFDFDFDFDULL,
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFDFDULL,
1004 0xFDFDFDFDFDFDFDFDULL,
1005 0xFDFDFDFDFDFDFD00ULL,
1006 0xFDFDFDFDFDFD0000ULL,
1007 0xFDFDFDFDFD000000ULL
1008 },
1009 {
1010 0xFDFDFDFDFDFDFDFDULL,
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFDFDULL,
1015 0xFDFDFDFDFDFDFDFDULL,
1016 0xFDFDFDFDFDFDFD00ULL,
1017 0xFDFDFDFDFDFD0000ULL
1018 },
1019 {
1020 0xFDFDFDFDFDFDFDFDULL,
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFDFDULL,
1026 0xFDFDFDFDFDFDFDFDULL,
1027 0xFDFDFDFDFDFDFD00ULL
1028 },
1029 {
1030 0xFDFDFDFDFDFDFDFDULL,
1031 0xFDFDFDFDFDFDFDFDULL,
1032 0xFDFDFDFDFDFDFDFDULL,
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL,
1035 0xFDFDFDFDFDFDFDFDULL,
1036 0xFDFDFDFDFDFDFDFDULL,
1037 0xFDFDFDFDFDFDFDFDULL
1038 }
1039 },
1040 {
1041 {
1042 0x0000000000000000ULL,
1043 0x0000000000000000ULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL,
1048 0x0000000000000000ULL,
1049 0x0000000000000000ULL
1050 },
1051 {
1052 0x00000000000000FDULL,
1053 0x0000000000000000ULL,
1054 0x0000000000000000ULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL,
1058 0x0000000000000000ULL,
1059 0x0000000000000000ULL
1060 },
1061 {
1062 0x000000000000FDFDULL,
1063 0x00000000000000FDULL,
1064 0x0000000000000000ULL,
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL
1070 },
1071 {
1072 0x0000000000FDFDFDULL,
1073 0x000000000000FDFDULL,
1074 0x00000000000000FDULL,
1075 0x0000000000000000ULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL
1080 },
1081 {
1082 0x00000000FDFDFDFDULL,
1083 0x0000000000FDFDFDULL,
1084 0x000000000000FDFDULL,
1085 0x00000000000000FDULL,
1086 0x0000000000000000ULL,
1087 0x0000000000000000ULL,
1088 0x0000000000000000ULL,
1089 0x0000000000000000ULL
1090 },
1091 {
1092 0x000000FDFDFDFDFDULL,
1093 0x00000000FDFDFDFDULL,
1094 0x0000000000FDFDFDULL,
1095 0x000000000000FDFDULL,
1096 0x00000000000000FDULL,
1097 0x0000000000000000ULL,
1098 0x0000000000000000ULL,
1099 0x0000000000000000ULL
1100 },
1101 {
1102 0x0000FDFDFDFDFDFDULL,
1103 0x000000FDFDFDFDFDULL,
1104 0x00000000FDFDFDFDULL,
1105 0x0000000000FDFDFDULL,
1106 0x000000000000FDFDULL,
1107 0x00000000000000FDULL,
1108 0x0000000000000000ULL,
1109 0x0000000000000000ULL
1110 },
1111 {
1112 0x00FDFDFDFDFDFDFDULL,
1113 0x0000FDFDFDFDFDFDULL,
1114 0x000000FDFDFDFDFDULL,
1115 0x00000000FDFDFDFDULL,
1116 0x0000000000FDFDFDULL,
1117 0x000000000000FDFDULL,
1118 0x00000000000000FDULL,
1119 0x0000000000000000ULL
1120 },
1121 {
1122 0xFDFDFDFDFDFDFDFDULL,
1123 0x00FDFDFDFDFDFDFDULL,
1124 0x0000FDFDFDFDFDFDULL,
1125 0x000000FDFDFDFDFDULL,
1126 0x00000000FDFDFDFDULL,
1127 0x0000000000FDFDFDULL,
1128 0x000000000000FDFDULL,
1129 0x00000000000000FDULL
1130 },
1131 {
1132 0xFDFDFDFDFDFDFDFDULL,
1133 0xFDFDFDFDFDFDFDFDULL,
1134 0x00FDFDFDFDFDFDFDULL,
1135 0x0000FDFDFDFDFDFDULL,
1136 0x000000FDFDFDFDFDULL,
1137 0x00000000FDFDFDFDULL,
1138 0x0000000000FDFDFDULL,
1139 0x000000000000FDFDULL
1140 },
1141 {
1142 0xFDFDFDFDFDFDFDFDULL,
1143 0xFDFDFDFDFDFDFDFDULL,
1144 0xFDFDFDFDFDFDFDFDULL,
1145 0x00FDFDFDFDFDFDFDULL,
1146 0x0000FDFDFDFDFDFDULL,
1147 0x000000FDFDFDFDFDULL,
1148 0x00000000FDFDFDFDULL,
1149 0x0000000000FDFDFDULL
1150 },
1151 {
1152 0xFDFDFDFDFDFDFDFDULL,
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0xFDFDFDFDFDFDFDFDULL,
1155 0xFDFDFDFDFDFDFDFDULL,
1156 0x00FDFDFDFDFDFDFDULL,
1157 0x0000FDFDFDFDFDFDULL,
1158 0x000000FDFDFDFDFDULL,
1159 0x00000000FDFDFDFDULL
1160 },
1161 {
1162 0xFDFDFDFDFDFDFDFDULL,
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0x00FDFDFDFDFDFDFDULL,
1168 0x0000FDFDFDFDFDFDULL,
1169 0x000000FDFDFDFDFDULL
1170 },
1171 {
1172 0xFDFDFDFDFDFDFDFDULL,
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0x00FDFDFDFDFDFDFDULL,
1179 0x0000FDFDFDFDFDFDULL
1180 },
1181 {
1182 0xFDFDFDFDFDFDFDFDULL,
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0x00FDFDFDFDFDFDFDULL
1190 },
1191 {
1192 0xFDFDFDFDFDFDFDFDULL,
1193 0xFDFDFDFDFDFDFDFDULL,
1194 0xFDFDFDFDFDFDFDFDULL,
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL,
1198 0xFDFDFDFDFDFDFDFDULL,
1199 0xFDFDFDFDFDFDFDFDULL
1200 }
1201 },
1202 {
1203 {
1204 0x0000000000000000ULL,
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL,
1210 0x0000000000000000ULL,
1211 0x0000000000000000ULL
1212 },
1213 {
1214 0x0000000000000000ULL,
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0x0000000000000000ULL,
1220 0x0000000000000000ULL,
1221 0xFD00000000000000ULL
1222 },
1223 {
1224 0x0000000000000000ULL,
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0xFD00000000000000ULL,
1231 0xFDFD000000000000ULL
1232 },
1233 {
1234 0x0000000000000000ULL,
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0x0000000000000000ULL,
1238 0x0000000000000000ULL,
1239 0xFD00000000000000ULL,
1240 0xFDFD000000000000ULL,
1241 0xFDFDFD0000000000ULL
1242 },
1243 {
1244 0x0000000000000000ULL,
1245 0x0000000000000000ULL,
1246 0x0000000000000000ULL,
1247 0x0000000000000000ULL,
1248 0xFD00000000000000ULL,
1249 0xFDFD000000000000ULL,
1250 0xFDFDFD0000000000ULL,
1251 0xFDFDFDFD00000000ULL
1252 },
1253 {
1254 0x0000000000000000ULL,
1255 0x0000000000000000ULL,
1256 0x0000000000000000ULL,
1257 0xFD00000000000000ULL,
1258 0xFDFD000000000000ULL,
1259 0xFDFDFD0000000000ULL,
1260 0xFDFDFDFD00000000ULL,
1261 0xFDFDFDFDFD000000ULL
1262 },
1263 {
1264 0x0000000000000000ULL,
1265 0x0000000000000000ULL,
1266 0xFD00000000000000ULL,
1267 0xFDFD000000000000ULL,
1268 0xFDFDFD0000000000ULL,
1269 0xFDFDFDFD00000000ULL,
1270 0xFDFDFDFDFD000000ULL,
1271 0xFDFDFDFDFDFD0000ULL
1272 },
1273 {
1274 0x0000000000000000ULL,
1275 0xFD00000000000000ULL,
1276 0xFDFD000000000000ULL,
1277 0xFDFDFD0000000000ULL,
1278 0xFDFDFDFD00000000ULL,
1279 0xFDFDFDFDFD000000ULL,
1280 0xFDFDFDFDFDFD0000ULL,
1281 0xFDFDFDFDFDFDFD00ULL
1282 },
1283 {
1284 0xFD00000000000000ULL,
1285 0xFDFD000000000000ULL,
1286 0xFDFDFD0000000000ULL,
1287 0xFDFDFDFD00000000ULL,
1288 0xFDFDFDFDFD000000ULL,
1289 0xFDFDFDFDFDFD0000ULL,
1290 0xFDFDFDFDFDFDFD00ULL,
1291 0xFDFDFDFDFDFDFDFDULL
1292 },
1293 {
1294 0xFDFD000000000000ULL,
1295 0xFDFDFD0000000000ULL,
1296 0xFDFDFDFD00000000ULL,
1297 0xFDFDFDFDFD000000ULL,
1298 0xFDFDFDFDFDFD0000ULL,
1299 0xFDFDFDFDFDFDFD00ULL,
1300 0xFDFDFDFDFDFDFDFDULL,
1301 0xFDFDFDFDFDFDFDFDULL
1302 },
1303 {
1304 0xFDFDFD0000000000ULL,
1305 0xFDFDFDFD00000000ULL,
1306 0xFDFDFDFDFD000000ULL,
1307 0xFDFDFDFDFDFD0000ULL,
1308 0xFDFDFDFDFDFDFD00ULL,
1309 0xFDFDFDFDFDFDFDFDULL,
1310 0xFDFDFDFDFDFDFDFDULL,
1311 0xFDFDFDFDFDFDFDFDULL
1312 },
1313 {
1314 0xFDFDFDFD00000000ULL,
1315 0xFDFDFDFDFD000000ULL,
1316 0xFDFDFDFDFDFD0000ULL,
1317 0xFDFDFDFDFDFDFD00ULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0xFDFDFDFDFDFDFDFDULL,
1320 0xFDFDFDFDFDFDFDFDULL,
1321 0xFDFDFDFDFDFDFDFDULL
1322 },
1323 {
1324 0xFDFDFDFDFD000000ULL,
1325 0xFDFDFDFDFDFD0000ULL,
1326 0xFDFDFDFDFDFDFD00ULL,
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0xFDFDFDFDFDFDFDFDULL,
1331 0xFDFDFDFDFDFDFDFDULL
1332 },
1333 {
1334 0xFDFDFDFDFDFD0000ULL,
1335 0xFDFDFDFDFDFDFD00ULL,
1336 0xFDFDFDFDFDFDFDFDULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0xFDFDFDFDFDFDFDFDULL
1342 },
1343 {
1344 0xFDFDFDFDFDFDFD00ULL,
1345 0xFDFDFDFDFDFDFDFDULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL
1352 },
1353 {
1354 0xFDFDFDFDFDFDFDFDULL,
1355 0xFDFDFDFDFDFDFDFDULL,
1356 0xFDFDFDFDFDFDFDFDULL,
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL,
1360 0xFDFDFDFDFDFDFDFDULL,
1361 0xFDFDFDFDFDFDFDFDULL
1362 }
1363 },
1364 {
1365 {
1366 0x0000000000000000ULL,
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL,
1372 0x0000000000000000ULL,
1373 0x0000000000000000ULL
1374 },
1375 {
1376 0x0000000000000000ULL,
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x0000000000000000ULL,
1382 0x0000000000000000ULL,
1383 0x00000000000000FDULL
1384 },
1385 {
1386 0x0000000000000000ULL,
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x00000000000000FDULL,
1393 0x000000000000FDFDULL
1394 },
1395 {
1396 0x0000000000000000ULL,
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x0000000000000000ULL,
1400 0x0000000000000000ULL,
1401 0x00000000000000FDULL,
1402 0x000000000000FDFDULL,
1403 0x0000000000FDFDFDULL
1404 },
1405 {
1406 0x0000000000000000ULL,
1407 0x0000000000000000ULL,
1408 0x0000000000000000ULL,
1409 0x0000000000000000ULL,
1410 0x00000000000000FDULL,
1411 0x000000000000FDFDULL,
1412 0x0000000000FDFDFDULL,
1413 0x00000000FDFDFDFDULL
1414 },
1415 {
1416 0x0000000000000000ULL,
1417 0x0000000000000000ULL,
1418 0x0000000000000000ULL,
1419 0x00000000000000FDULL,
1420 0x000000000000FDFDULL,
1421 0x0000000000FDFDFDULL,
1422 0x00000000FDFDFDFDULL,
1423 0x000000FDFDFDFDFDULL
1424 },
1425 {
1426 0x0000000000000000ULL,
1427 0x0000000000000000ULL,
1428 0x00000000000000FDULL,
1429 0x000000000000FDFDULL,
1430 0x0000000000FDFDFDULL,
1431 0x00000000FDFDFDFDULL,
1432 0x000000FDFDFDFDFDULL,
1433 0x0000FDFDFDFDFDFDULL
1434 },
1435 {
1436 0x0000000000000000ULL,
1437 0x00000000000000FDULL,
1438 0x000000000000FDFDULL,
1439 0x0000000000FDFDFDULL,
1440 0x00000000FDFDFDFDULL,
1441 0x000000FDFDFDFDFDULL,
1442 0x0000FDFDFDFDFDFDULL,
1443 0x00FDFDFDFDFDFDFDULL
1444 },
1445 {
1446 0x00000000000000FDULL,
1447 0x000000000000FDFDULL,
1448 0x0000000000FDFDFDULL,
1449 0x00000000FDFDFDFDULL,
1450 0x000000FDFDFDFDFDULL,
1451 0x0000FDFDFDFDFDFDULL,
1452 0x00FDFDFDFDFDFDFDULL,
1453 0xFDFDFDFDFDFDFDFDULL
1454 },
1455 {
1456 0x000000000000FDFDULL,
1457 0x0000000000FDFDFDULL,
1458 0x00000000FDFDFDFDULL,
1459 0x000000FDFDFDFDFDULL,
1460 0x0000FDFDFDFDFDFDULL,
1461 0x00FDFDFDFDFDFDFDULL,
1462 0xFDFDFDFDFDFDFDFDULL,
1463 0xFDFDFDFDFDFDFDFDULL
1464 },
1465 {
1466 0x0000000000FDFDFDULL,
1467 0x00000000FDFDFDFDULL,
1468 0x000000FDFDFDFDFDULL,
1469 0x0000FDFDFDFDFDFDULL,
1470 0x00FDFDFDFDFDFDFDULL,
1471 0xFDFDFDFDFDFDFDFDULL,
1472 0xFDFDFDFDFDFDFDFDULL,
1473 0xFDFDFDFDFDFDFDFDULL
1474 },
1475 {
1476 0x00000000FDFDFDFDULL,
1477 0x000000FDFDFDFDFDULL,
1478 0x0000FDFDFDFDFDFDULL,
1479 0x00FDFDFDFDFDFDFDULL,
1480 0xFDFDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL,
1482 0xFDFDFDFDFDFDFDFDULL,
1483 0xFDFDFDFDFDFDFDFDULL
1484 },
1485 {
1486 0x000000FDFDFDFDFDULL,
1487 0x0000FDFDFDFDFDFDULL,
1488 0x00FDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL,
1492 0xFDFDFDFDFDFDFDFDULL,
1493 0xFDFDFDFDFDFDFDFDULL
1494 },
1495 {
1496 0x0000FDFDFDFDFDFDULL,
1497 0x00FDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL,
1502 0xFDFDFDFDFDFDFDFDULL,
1503 0xFDFDFDFDFDFDFDFDULL
1504 },
1505 {
1506 0x00FDFDFDFDFDFDFDULL,
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL,
1512 0xFDFDFDFDFDFDFDFDULL,
1513 0xFDFDFDFDFDFDFDFDULL
1514 },
1515 {
1516 0xFDFDFDFDFDFDFDFDULL,
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL,
1521 0xFDFDFDFDFDFDFDFDULL,
1522 0xFDFDFDFDFDFDFDFDULL,
1523 0xFDFDFDFDFDFDFDFDULL
1524 }
1525 }
1526 };
1527
1528 static bool is_opening_screen;
1529 int32_t black_opening_count=0;
1530 int32_t black_opening_x,black_opening_y;
1531 int32_t black_opening_shape;
1532
1533 3283 int32_t choose_opening_shape()
1534 {
1535 // First, count how many bits are set
1536 3283 int32_t numBits=0;
1537 int32_t bitCounter;
1538
1539
2/2
✓ Branch 0 taken 16415 times.
✓ Branch 1 taken 3283 times.
19698 for(int32_t i=0; i<bosMAX; i++)
1540 {
1541
2/2
✓ Branch 0 taken 12916 times.
✓ Branch 1 taken 3499 times.
16415 if(COOLSCROLL&(1<<i))
1542 3499 numBits++;
1543 16415 }
1544
1545 // Shouldn't happen...
1546
1/2
✓ Branch 0 taken 3283 times.
✗ Branch 1 not taken.
3283 if(numBits==0)
1547 return bosCIRCLE;
1548
1549 // Pick a bit
1550 3283 bitCounter=zc_rand()%numBits+1;
1551
1552
2/2
✓ Branch 0 taken 4477 times.
✓ Branch 1 taken 26 times.
4503 for(int32_t i=0; i<bosMAX; i++)
1553 {
1554 // If this bit is set, decrement the bit counter
1555
2/2
✓ Branch 0 taken 1064 times.
✓ Branch 1 taken 3413 times.
4477 if(COOLSCROLL&(1<<i))
1556 3413 bitCounter--;
1557
1558 // When the counter hits 0, return a value based on
1559 // which bit it stopped on.
1560 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1561
2/2
✓ Branch 0 taken 3257 times.
✓ Branch 1 taken 1220 times.
4477 if(bitCounter==0)
1562 3257 return i;
1563 1220 }
1564
1565 // Shouldn't be necessary, but the compiler might complain, at least
1566 26 return bosCIRCLE;
1567 3283 }
1568
1569 739 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1570 {
1571 739 x -= viewport.x;
1572 739 y -= viewport.y;
1573
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 729 times.
739 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1574
1575 739 int32_t w=framebuf->w, h=framebuf->h;
1576 739 int32_t blockrows=h/8, blockcolumns=32;
1577 739 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1578
1579
2/2
✓ Branch 0 taken 20692 times.
✓ Branch 1 taken 739 times.
21431 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1580 {
1581
2/2
✓ Branch 0 taken 662144 times.
✓ Branch 1 taken 20692 times.
682836 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1582 {
1583
2/2
✓ Branch 0 taken 273677 times.
✓ Branch 1 taken 388467 times.
662144 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1584 662144 }
1585 20692 }
1586
1587 739 black_opening_count = 66;
1588 739 black_opening_x = x;
1589 739 black_opening_y = y;
1590 739 lensclk = 0;
1591 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1592
1593
1594
1/2
✓ Branch 0 taken 739 times.
✗ Branch 1 not taken.
739 if(black_opening_shape == bosFADEBLACK)
1595 {
1596 refreshTints();
1597 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1598 }
1599
2/2
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 14 times.
739 if(wait)
1600 {
1601 14 FFCore.warpScriptCheck();
1602
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 924 times.
938 for(int32_t i=0; i<66; i++)
1603 {
1604 924 draw_screen();
1605 924 advanceframe(true);
1606
1607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 924 times.
924 if(Quit)
1608 {
1609 break;
1610 }
1611 924 }
1612 14 }
1613 739 }
1614
1615 2564 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1616 {
1617 2564 x -= viewport.x;
1618 2564 y -= viewport.y;
1619
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2554 times.
2564 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1620
1621 2564 int32_t w=framebuf->w, h=framebuf->h;
1622 2564 int32_t blockrows=h/8, blockcolumns=32;
1623 2564 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1624
1625
2/2
✓ Branch 0 taken 71905 times.
✓ Branch 1 taken 2564 times.
74469 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1626 {
1627
2/2
✓ Branch 0 taken 2300960 times.
✓ Branch 1 taken 71905 times.
2372865 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1628 {
1629
2/2
✓ Branch 0 taken 1134289 times.
✓ Branch 1 taken 1166671 times.
2300960 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1630 2300960 }
1631 71905 }
1632
1633 2564 black_opening_count = -66;
1634 2564 black_opening_x = x;
1635 2564 black_opening_y = y;
1636 2564 lensclk = 0;
1637
1/2
✓ Branch 0 taken 2564 times.
✗ Branch 1 not taken.
2564 if(black_opening_shape == bosFADEBLACK)
1638 {
1639 refreshTints();
1640 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1641 }
1642
2/2
✓ Branch 0 taken 361 times.
✓ Branch 1 taken 2203 times.
2564 if(wait)
1643 {
1644 2203 FFCore.warpScriptCheck();
1645
2/2
✓ Branch 0 taken 2202 times.
✓ Branch 1 taken 145409 times.
147611 for(int32_t i=0; i<66; i++)
1646 {
1647 145409 draw_screen();
1648 145409 advanceframe(true);
1649
1650
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 145408 times.
145409 if(Quit)
1651 {
1652 1 break;
1653 }
1654 145408 }
1655 2203 }
1656 2564 }
1657
1658 217685 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1659 {
1660 217685 clear_to_color(tmp_scr,BLACK);
1661 217685 int32_t w=dest->w, h=dest->h;
1662
1663
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 1980 times.
✓ Branch 3 taken 20328 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 185741 times.
217685 switch(black_opening_shape)
1664 {
1665 case bosOVAL:
1666 {
1667 9636 double new_w=(w/2)+abs(w/2-x);
1668 9636 double new_h=(h/2)+abs(h/2-y);
1669 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1670 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1671 9636 break;
1672 }
1673
1674 case bosTRIANGLE:
1675 {
1676 1980 double new_w=(w/2)+abs(w/2-x);
1677 1980 double new_h=(h/2)+abs(h/2-y);
1678 1980 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1679 1980 double P2= (PI/2);
1680 1980 double P23=(2*PI/3);
1681 1980 double P43=(4*PI/3);
1682 1980 double Pa= (-4*PI*a/(3*max_a));
1683 1980 double angle=P2+Pa;
1684 1980 double a0=angle;
1685 1980 double a2=angle+P23;
1686 1980 double a4=angle+P43;
1687 3960 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1688 1980 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1689 1980 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1690 0);
1691 1980 break;
1692 }
1693
1694 case bosSMAS:
1695 {
1696
2/2
✓ Branch 0 taken 7260 times.
✓ Branch 1 taken 13068 times.
20328 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1697
1698
2/2
✓ Branch 0 taken 569184 times.
✓ Branch 1 taken 20328 times.
589512 for(int32_t blockrow=0; blockrow<h/8; ++blockrow) //30
1699 {
1700
2/2
✓ Branch 0 taken 4553472 times.
✓ Branch 1 taken 569184 times.
5122656 for(int32_t linerow=0; linerow<8; ++linerow)
1701 {
1702 4553472 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1703
1704
2/2
✓ Branch 0 taken 145711104 times.
✓ Branch 1 taken 4553472 times.
150264576 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1705 {
1706 437133312 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1707
6/6
✓ Branch 0 taken 105268072 times.
✓ Branch 1 taken 40443032 times.
✓ Branch 2 taken 96140976 times.
✓ Branch 3 taken 49570128 times.
✓ Branch 4 taken 55697944 times.
✓ Branch 5 taken 40443032 times.
145711104 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1708 145711104 [linerow];
1709 145711104 ++triangleline;
1710 145711104 }
1711 4553472 }
1712 569184 }
1713
1714 20328 break;
1715 }
1716
1717 case bosFADEBLACK:
1718 {
1719 if(black_opening_count<0)
1720 {
1721 black_fade(zc_min(-black_opening_count,63));
1722 }
1723 else if(black_opening_count>0)
1724 {
1725 black_fade(63-zc_max(black_opening_count-3,0));
1726 }
1727 else black_fade(0);
1728 return; //no blitting from tmp_scr!
1729 }
1730
1731 185741 case bosCIRCLE:
1732 default:
1733 {
1734 185741 double new_w=(w/2)+abs(w/2-x);
1735 185741 double new_h=(h/2)+abs(h/2-y);
1736 185741 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1737 //circlefill(tmp_scr,x,y,a<<3,0);
1738 185741 circlefill(tmp_scr,x,y,r,0);
1739 185741 break;
1740 }
1741 }
1742
1743 217685 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1744 217685 }
1745
1746 // fadeamnt is 0-63
1747 void black_fade(int32_t fadeamnt)
1748 {
1749 fadeamnt = _rgb_scale_6[fadeamnt];
1750 for(int32_t i=0; i < 0xEF; i++)
1751 {
1752 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1753 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1754 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1755 }
1756
1757 refreshpal = true;
1758 }
1759
1760 //----------------------------------------------------------------
1761
1762 201317334 bool item_disabled(int32_t item) //is this item disabled?
1763 {
1764
2/2
✓ Branch 0 taken 14531591 times.
✓ Branch 1 taken 186785743 times.
201317334 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1765 }
1766
1767 15648722 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1768 {
1769
2/2
✓ Branch 0 taken 254624 times.
✓ Branch 1 taken 15394098 times.
15648722 if(current_item(item_type, true) >=item)
1770 {
1771 254624 return true;
1772 }
1773
1774 15394098 return false;
1775 15648722 }
1776
1777 43612664 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1778 {
1779
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421308 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 337472 times.
✓ Branch 6 taken 28758369 times.
✓ Branch 7 taken 9900449 times.
✓ Branch 8 taken 195066 times.
43612664 switch(item_type)
1780 {
1781 case itype_bomb:
1782 case itype_sbomb:
1783 {
1784 int32_t itemid = getItemID(itemsbuf, item_type, it);
1785
1786 if(itemid == -1)
1787 return false;
1788
1789 return (game->get_item(itemid));
1790 }
1791
1792 case itype_clock:
1793 {
1794 4421308 int32_t itemid = getItemID(itemsbuf, item_type, it);
1795
1796
2/4
✓ Branch 0 taken 4421308 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421308 times.
✗ Branch 3 not taken.
4421308 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1797 return (game->get_item(itemid));
1798 4421308 return Hero.getClock()?1:0;
1799 }
1800
1801 case itype_key:
1802 return (game->get_keys()>0);
1803
1804 case itype_magiccontainer:
1805 return (game->get_maxmagic()>=game->get_mp_per_block());
1806
1807 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1808 {
1809
1/3
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
337472 switch(it)
1810 {
1811 case -2:
1812 {
1813 for(int32_t i=0; i<MAXLEVELS; i++)
1814 {
1815 if(game->lvlitems[i]&(1 << li_mcguffin))
1816 {
1817 return true;
1818 }
1819 }
1820
1821 return false;
1822 }
1823
1824 case -1:
1825 return (game->lvlitems[dlevel]&(1 << li_mcguffin));
1826
1827 default:
1828
2/4
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 337472 times.
337472 if(it>=0&&it<MAXLEVELS)
1829 {
1830 337472 return (game->lvlitems[it]&(1 << li_mcguffin));
1831 }
1832
1833 break;
1834 }
1835
1836 return 0;
1837 }
1838
1839 case itype_map: //it: -2=any, -1=current level, other=that level
1840 {
1841
2/3
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28216743 times.
28758369 switch(it)
1842 {
1843 case -2:
1844 {
1845 for(int32_t i=0; i<MAXLEVELS; i++)
1846 {
1847 if(game->lvlitems[i]&(1 << li_map))
1848 {
1849 return true;
1850 }
1851 }
1852
1853 return false;
1854 }
1855
1856 case -1:
1857 28216743 return (game->lvlitems[dlevel]&(1 << li_map))!=0;
1858
1859 default:
1860
2/4
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 541626 times.
541626 if(it>=0&&it<MAXLEVELS)
1861 {
1862 541626 return (game->lvlitems[it]&(1 << li_map))!=0;
1863 }
1864
1865 break;
1866 }
1867
1868 return 0;
1869 }
1870
1871 case itype_compass: //it: -2=any, -1=current level, other=that level
1872 {
1873
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9900449 times.
9900449 switch(it)
1874 {
1875 case -2:
1876 {
1877 for(int32_t i=0; i<MAXLEVELS; i++)
1878 {
1879 if(game->lvlitems[i]&(1 << li_compass))
1880 {
1881 return true;
1882 }
1883 }
1884
1885 return false;
1886 }
1887
1888 case -1:
1889 9900449 return (game->lvlitems[dlevel]&(1 << li_compass))!=0;
1890
1891 default:
1892 if(it>=0&&it<MAXLEVELS)
1893 {
1894 return (game->lvlitems[it]&(1 << li_compass))!=0;
1895 }
1896
1897 break;
1898 }
1899 return 0;
1900 }
1901
1902 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1903 {
1904
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 195066 times.
195066 switch(it)
1905 {
1906 case -2:
1907 {
1908 for(int32_t i=0; i<MAXLEVELS; i++)
1909 {
1910 if(game->lvlitems[i]&(1 << li_boss_key))
1911 {
1912 return true;
1913 }
1914 }
1915
1916 return false;
1917 }
1918
1919 case -1:
1920 195066 return (game->lvlitems[dlevel]&(1 << li_boss_key))?1:0;
1921
1922 default:
1923 if(it>=0&&it<MAXLEVELS)
1924 {
1925 return (game->lvlitems[it]&(1 << li_boss_key))?1:0;
1926 }
1927 break;
1928 }
1929 return 0;
1930 }
1931
1932 default:
1933 int32_t itemid = getItemID(itemsbuf, item_type, it);
1934
1935 if(itemid == -1)
1936 return false;
1937
1938 return game->get_item(itemid);
1939 }
1940 43612664 }
1941
1942 151022785 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1943 {
1944
9/9
✓ Branch 0 taken 4421308 times.
✓ Branch 1 taken 115652321 times.
✓ Branch 2 taken 4421308 times.
✓ Branch 3 taken 4421308 times.
✓ Branch 4 taken 4421308 times.
✓ Branch 5 taken 4421308 times.
✓ Branch 6 taken 4421308 times.
✓ Branch 7 taken 4421308 times.
✓ Branch 8 taken 4421308 times.
151022785 switch(item_type)
1945 {
1946 case itype_clock:
1947 {
1948 4421308 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1949
1950
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4421308 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4421308 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1951 return itemsbuf[maxid].level;
1952
1953 4421308 return has_item(itype_clock,1) ? 1 : 0;
1954 }
1955
1956 case itype_key:
1957 4421308 return game->get_keys();
1958
1959 case itype_lkey:
1960 4421308 return game->lvlkeys[get_dlevel()];
1961
1962 case itype_magiccontainer:
1963 4421308 return game->get_maxmagic()/game->get_mp_per_block();
1964
1965 case itype_triforcepiece:
1966 {
1967 4421308 int count=0;
1968
1969
2/2
✓ Branch 0 taken 2263709696 times.
✓ Branch 1 taken 4421308 times.
2268131004 for(int i=0; i<MAXLEVELS; i++)
1970 {
1971 2263709696 count+=(game->lvlitems[i]&(1 << li_mcguffin))?1:0;
1972 2263709696 }
1973
1974 4421308 return count;
1975 }
1976
1977 case itype_map:
1978 {
1979 4421308 int count=0;
1980
1981
2/2
✓ Branch 0 taken 2263709696 times.
✓ Branch 1 taken 4421308 times.
2268131004 for(int i=0; i<MAXLEVELS; i++)
1982 {
1983 2263709696 count+=(game->lvlitems[i]&(1 << li_map))?1:0;
1984 2263709696 }
1985
1986 4421308 return count;
1987 }
1988
1989 case itype_compass:
1990 {
1991 4421308 int count=0;
1992
1993
2/2
✓ Branch 0 taken 2263709696 times.
✓ Branch 1 taken 4421308 times.
2268131004 for(int i=0; i<MAXLEVELS; i++)
1994 {
1995 2263709696 count+=(game->lvlitems[i]&(1 << li_compass))?1:0;
1996 2263709696 }
1997
1998 4421308 return count;
1999 }
2000
2001 case itype_bosskey:
2002 {
2003 4421308 int count=0;
2004
2005
2/2
✓ Branch 0 taken 2263709696 times.
✓ Branch 1 taken 4421308 times.
2268131004 for(int i=0; i<MAXLEVELS; i++)
2006 {
2007 2263709696 count+=(game->lvlitems[i]&(1 << li_boss_key))?1:0;
2008 2263709696 }
2009
2010 4421308 return count;
2011 }
2012
2013 default:
2014 115652321 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2015
2016
2/2
✓ Branch 0 taken 81959343 times.
✓ Branch 1 taken 33692978 times.
115652321 if(maxid == -1)
2017 81959343 return 0;
2018
2019 33692978 return itemsbuf[maxid].level;
2020 }
2021 151022785 }
2022
2023 416 std::map<int32_t, int32_t> itemcache;
2024 416 std::map<int32_t, int32_t> itemcache_cost;
2025
2026 void removeFromItemCache(int32_t itemclass)
2027 {
2028 itemcache.erase(itemclass);
2029 itemcache_cost.erase(itemclass);
2030 cache_tile_mod_clear();
2031 }
2032
2033 13059184 void flushItemCache(bool justcost)
2034 {
2035 13059184 itemcache_cost.clear();
2036
2/2
✓ Branch 0 taken 12985544 times.
✓ Branch 1 taken 73640 times.
13059184 if(!justcost)
2037 73640 itemcache.clear();
2038
2/2
✓ Branch 0 taken 6357348 times.
✓ Branch 1 taken 6628196 times.
12985544 else if(replay_version_check(0,19))
2039 6357348 return;
2040
2041 6701836 cache_tile_mod_clear();
2042
2043 //also fix the active subscreen if items were deleted -DD
2044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6701836 times.
6701836 if(game != NULL)
2045 {
2046 6701836 verifyBothWeapons();
2047 6701836 refresh_subscr_items();
2048 6701836 }
2049 13059184 }
2050
2051 // This is used often, so it should be as direct as possible.
2052 3049354971 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2053 {
2054 3049354971 bool use_cost_cache = replay_version_check(19);
2055
2/2
✓ Branch 0 taken 2909423948 times.
✓ Branch 1 taken 139931023 times.
3049354971 if(jinx_check)
2056 {
2057 //special case for shields...
2058
3/4
✓ Branch 0 taken 54394443 times.
✓ Branch 1 taken 85536580 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54394443 times.
139931023 if (itemtype == itype_shield && !HeroShieldClk())
2059 54394443 jinx_check = false;
2060
4/4
✓ Branch 0 taken 52598029 times.
✓ Branch 1 taken 32938551 times.
✓ Branch 2 taken 10934442 times.
✓ Branch 3 taken 41663587 times.
85536580 else if(!(HeroSwordClk() || HeroItemClk()))
2061 41663587 jinx_check = false; //not jinxed
2062 139931023 }
2063
4/4
✓ Branch 0 taken 121490 times.
✓ Branch 1 taken 3049233481 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 119637 times.
3049354971 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2064 3049235334 check_bunny = false;
2065
2/2
✓ Branch 0 taken 2991590997 times.
✓ Branch 1 taken 57763974 times.
3049354971 if(itemtype == itype_ring) checkmagic = true;
2066
4/4
✓ Branch 0 taken 3005481978 times.
✓ Branch 1 taken 43872993 times.
✓ Branch 2 taken 310646637 times.
✓ Branch 3 taken 25152461 times.
3385154069 if (!jinx_check && !check_bunny
2067
4/4
✓ Branch 0 taken 3005389949 times.
✓ Branch 1 taken 92029 times.
✓ Branch 2 taken 335799098 times.
✓ Branch 3 taken 2669590851 times.
3005481978 && (use_cost_cache || itemtype != itype_ring))
2068 {
2069
4/4
✓ Branch 0 taken 586720921 times.
✓ Branch 1 taken 2393516567 times.
✓ Branch 2 taken 260166163 times.
✓ Branch 3 taken 326554758 times.
2980237488 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2070 2980237488 auto res = cache.find(itemtype);
2071
2072
2/2
✓ Branch 0 taken 2829504895 times.
✓ Branch 1 taken 150732593 times.
2980237488 if(res != cache.end())
2073 2829504895 return res->second;
2074 150732593 }
2075
2076 219850076 int result = -1;
2077 219850076 int highestlevel = -1;
2078
2079
2/2
✓ Branch 0 taken 56281619456 times.
✓ Branch 1 taken 219850076 times.
56501469532 for(int i=0; i<MAXITEMS; i++)
2080 {
2081
6/6
✓ Branch 0 taken 6172686610 times.
✓ Branch 1 taken 50108932846 times.
✓ Branch 2 taken 96239195 times.
✓ Branch 3 taken 6076447415 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 96157147 times.
56281619456 if(game->get_item(i) && itemsbuf[i].type==itemtype && !item_disabled(i))
2082 {
2083
4/4
✓ Branch 0 taken 91482648 times.
✓ Branch 1 taken 4674499 times.
✓ Branch 2 taken 2473305 times.
✓ Branch 3 taken 89009343 times.
96157147 if(checkmagic && itemtype != itype_magicring)
2084
2/2
✓ Branch 0 taken 89008642 times.
✓ Branch 1 taken 701 times.
89009343 if(!checkmagiccost(i))
2085 701 continue;
2086
6/6
✓ Branch 0 taken 88697159 times.
✓ Branch 1 taken 7459287 times.
✓ Branch 2 taken 1257252 times.
✓ Branch 3 taken 6202035 times.
✓ Branch 4 taken 4066904 times.
✓ Branch 5 taken 3392383 times.
96156446 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3392383 times.
3392383 if(!(itemsbuf[i].flags & item_jinx_immune))
2088 3392383 continue;
2089
3/4
✓ Branch 0 taken 96967 times.
✓ Branch 1 taken 92667096 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 96967 times.
92764063 if(check_bunny && !checkbunny(i))
2090 96967 continue;
2091
2092
2/2
✓ Branch 0 taken 8438993 times.
✓ Branch 1 taken 84228103 times.
92667096 if(itemsbuf[i].level >= highestlevel)
2093 {
2094 84228103 highestlevel = itemsbuf[i].level;
2095 84228103 result=i;
2096 84228103 }
2097 92667096 }
2098 56278129405 }
2099
2100
4/4
✓ Branch 0 taken 175977083 times.
✓ Branch 1 taken 43872993 times.
✓ Branch 2 taken 92029 times.
✓ Branch 3 taken 175885054 times.
219850076 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2101 {
2102
2/2
✓ Branch 0 taken 134117067 times.
✓ Branch 1 taken 41767987 times.
175885054 if (use_cost_cache)
2103 {
2104
2/2
✓ Branch 0 taken 118202528 times.
✓ Branch 1 taken 15914539 times.
134117067 if (!checkmagic)
2105 15914539 itemcache[itemtype] = result;
2106
6/6
✓ Branch 0 taken 15914539 times.
✓ Branch 1 taken 118202528 times.
✓ Branch 2 taken 688511 times.
✓ Branch 3 taken 15226028 times.
✓ Branch 4 taken 673550 times.
✓ Branch 5 taken 14961 times.
134117067 if (checkmagic || result < 0 || checkmagiccost(result))
2107 134102106 itemcache_cost[itemtype] = result;
2108 134117067 }
2109 else
2110 {
2111 41767987 itemcache[itemtype] = result;
2112 }
2113 175885054 }
2114 219850076 return result;
2115 3049354971 }
2116
2117 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2118 3022795331 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2119 {
2120
3/4
✓ Branch 0 taken 3005984102 times.
✓ Branch 1 taken 16811229 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3005984102 times.
3022795331 if(itype < 0 || itype >= itype_max) return -1;
2121
1/2
✓ Branch 0 taken 3005984102 times.
✗ Branch 1 not taken.
3005984102 if(game->OverrideItems[itype] > -2)
2122 {
2123 auto ovid = game->OverrideItems[itype];
2124 if(ovid < 0 || ovid >= MAXITEMS)
2125 return -1;
2126 if(itemsbuf[ovid].type == itype)
2127 {
2128 if(itype == itype_magicring)
2129 checkmagic = false;
2130 else if(itype == itype_ring)
2131 checkmagic = true;
2132
2133 if(checkmagic && !checkmagiccost(ovid))
2134 return -1;
2135
2136 if (jinx_check && !checkitem_jinx(ovid))
2137 {
2138 return -1;
2139 }
2140 return ovid;
2141 }
2142 }
2143 3005984102 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2144
2/2
✓ Branch 0 taken 96560154 times.
✓ Branch 1 taken 2909423948 times.
3005984102 if(!jinx_check) //If not already a jinx-immune-only check...
2145 {
2146 //And the player IS jinxed...
2147
2/2
✓ Branch 0 taken 2866053079 times.
✓ Branch 1 taken 43370869 times.
2909423948 if(HeroIsJinxed())
2148 {
2149 //Then do a jinx-immune-only check here
2150 43370869 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2151 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2152 //Should NOT need a compat rule, as this should always return -1 in old quests.
2153
2/2
✓ Branch 0 taken 3185385 times.
✓ Branch 1 taken 40185484 times.
43370869 if(ret2 > -1) return ret2;
2154 40185484 }
2155 2906238563 }
2156 3002798717 return ret;
2157 3022795331 }
2158
2159 66341627 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2160 {
2161 66341627 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2162
2/2
✓ Branch 0 taken 35534233 times.
✓ Branch 1 taken 30807394 times.
66341627 return (result<0) ? 0 : itemsbuf[result].power;
2163 }
2164
2165 26 int32_t heart_container_id()
2166 {
2167
1/2
✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
754 for(int32_t i=0; i<MAXITEMS; i++)
2168 {
2169
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 728 times.
754 if(itemsbuf[i].type == itype_heartcontainer)
2170 {
2171 26 return i;
2172 }
2173 728 }
2174 return -1;
2175 26 }
2176
2177 struct tilemod_cache_state_t
2178 {
2179
6/6
✓ Branch 0 taken 4420952 times.
✓ Branch 1 taken 8543212 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8543210 times.
✓ Branch 4 taken 354 times.
✓ Branch 5 taken 8542856 times.
21507376 bool operator==(const tilemod_cache_state_t&) const = default;
2180
2181 bool valid;
2182 bool bunny_clock;
2183 bool superman;
2184 int shield;
2185 };
2186 tilemod_cache_state_t tilemod_cache_state;
2187 int32_t tilemod_cache_value;
2188
2189 6703390 void cache_tile_mod_clear()
2190 {
2191 6703390 tilemod_cache_state = {false};
2192 6703390 }
2193
2194 12964164 int32_t item_tile_mod()
2195 {
2196 51856656 tilemod_cache_state_t state = {
2197 .valid = true,
2198 12964164 .bunny_clock = Hero.BunnyClock() != 0,
2199 12964164 .superman = Hero.superman,
2200 12964164 .shield = Hero.active_shield_id,
2201 };
2202
2/2
✓ Branch 0 taken 8542856 times.
✓ Branch 1 taken 4421308 times.
12964164 if (tilemod_cache_state == state)
2203 8542856 return tilemod_cache_value;
2204
2205 4421308 int32_t tile=0;
2206 4421308 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2207
4/4
✓ Branch 0 taken 4007992 times.
✓ Branch 1 taken 413316 times.
✓ Branch 2 taken 3079194 times.
✓ Branch 3 taken 928798 times.
4421308 if(check_bombcost || game->get_bombs())
2208 {
2209 3492510 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2210
3/4
✓ Branch 0 taken 3432971 times.
✓ Branch 1 taken 59539 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3432971 times.
3492510 if(itemid > -1 && checkbunny(itemid))
2211 3432971 tile+=itemsbuf[itemid].ltm;
2212 3492510 }
2213
2214
4/4
✓ Branch 0 taken 4007992 times.
✓ Branch 1 taken 413316 times.
✓ Branch 2 taken 965298 times.
✓ Branch 3 taken 3042694 times.
4421308 if(check_bombcost || game->get_sbombs())
2215 {
2216 1378614 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2217
3/4
✓ Branch 0 taken 965057 times.
✓ Branch 1 taken 413557 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 965057 times.
1378614 if(itemid > -1 && checkbunny(itemid))
2218 965057 tile+=itemsbuf[itemid].ltm;
2219 1378614 }
2220
2221
2/2
✓ Branch 0 taken 4408572 times.
✓ Branch 1 taken 12736 times.
4421308 if(current_item(itype_clock))
2222 {
2223 12736 int32_t itemid =
2224
2/2
✓ Branch 0 taken 12704 times.
✓ Branch 1 taken 32 times.
12736 get_qr(qr_HARDCODED_LITEM_LTMS)
2225 ? iClock
2226 32 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2227
2/4
✓ Branch 0 taken 12736 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12736 times.
12736 if(itemid > -1 && checkbunny(itemid))
2228 12736 tile+=itemsbuf[itemid].ltm;
2229 12736 }
2230
2231
2/2
✓ Branch 0 taken 3775666 times.
✓ Branch 1 taken 645642 times.
4421308 if(current_item(itype_key))
2232 {
2233 645642 int32_t itemid =
2234
2/2
✓ Branch 0 taken 608640 times.
✓ Branch 1 taken 37002 times.
645642 get_qr(qr_HARDCODED_LITEM_LTMS)
2235 ? iKey
2236 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2237
2/4
✓ Branch 0 taken 645642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 645642 times.
645642 if(itemid > -1 && checkbunny(itemid))
2238 645642 tile+=itemsbuf[itemid].ltm;
2239 645642 }
2240
2241
2/2
✓ Branch 0 taken 3920424 times.
✓ Branch 1 taken 500884 times.
4421308 if(current_item(itype_lkey))
2242 {
2243 500884 int32_t itemid =
2244
2/2
✓ Branch 0 taken 414169 times.
✓ Branch 1 taken 86715 times.
500884 get_qr(qr_HARDCODED_LITEM_LTMS)
2245 ? iLevelKey
2246 86715 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2247
2/4
✓ Branch 0 taken 500884 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500884 times.
500884 if(itemid > -1 && checkbunny(itemid))
2248 500884 tile+=itemsbuf[itemid].ltm;
2249 500884 }
2250
2251
2/2
✓ Branch 0 taken 1586478 times.
✓ Branch 1 taken 2834830 times.
4421308 if(current_item(itype_map))
2252 {
2253 2834830 int32_t itemid =
2254
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 10996 times.
2834830 get_qr(qr_HARDCODED_LITEM_LTMS)
2255 ? iMap
2256 10996 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2257
2/4
✓ Branch 0 taken 2834830 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2834830 times.
2834830 if(itemid > -1 && checkbunny(itemid))
2258 2834830 tile+=itemsbuf[itemid].ltm;
2259 2834830 }
2260
2261
2/2
✓ Branch 0 taken 2109319 times.
✓ Branch 1 taken 2311989 times.
4421308 if(current_item(itype_compass))
2262 {
2263 2311989 int32_t itemid =
2264
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2265 ? iCompass
2266 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2267
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2268 2311989 tile+=itemsbuf[itemid].ltm;
2269 2311989 }
2270
2271
2/2
✓ Branch 0 taken 1334892 times.
✓ Branch 1 taken 3086416 times.
4421308 if(current_item(itype_bosskey))
2272 {
2273 3086416 int32_t itemid =
2274
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2275 ? iBossKey
2276 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2277
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2278 3086416 tile+=itemsbuf[itemid].ltm;
2279 3086416 }
2280
2281
2/2
✓ Branch 0 taken 48314 times.
✓ Branch 1 taken 4372994 times.
4421308 if(current_item(itype_magiccontainer))
2282 {
2283 4372994 int32_t itemid =
2284
2/2
✓ Branch 0 taken 3904336 times.
✓ Branch 1 taken 468658 times.
4372994 get_qr(qr_HARDCODED_LITEM_LTMS)
2285 ? iMagicC
2286 468658 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2287
3/4
✓ Branch 0 taken 4372994 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4372977 times.
4372994 if(itemid > -1 && checkbunny(itemid))
2288 4372977 tile+=itemsbuf[itemid].ltm;
2289 4372994 }
2290
2291
2/2
✓ Branch 0 taken 1314828 times.
✓ Branch 1 taken 3106480 times.
4421308 if(current_item(itype_triforcepiece))
2292 {
2293 3106480 int32_t itemid =
2294
2/2
✓ Branch 0 taken 3069478 times.
✓ Branch 1 taken 37002 times.
3106480 get_qr(qr_HARDCODED_LITEM_LTMS)
2295 ? iTriforce
2296 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2297
2/4
✓ Branch 0 taken 3106480 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3106480 times.
3106480 if(itemid > -1 && checkbunny(itemid))
2298 3106480 tile+=itemsbuf[itemid].ltm;
2299 3106480 }
2300
2301
2/2
✓ Branch 0 taken 2263709696 times.
✓ Branch 1 taken 4421308 times.
2268131004 for(int32_t i=0; i<itype_max; i++)
2302 {
2303
2/2
✓ Branch 0 taken 2023628800 times.
✓ Branch 1 taken 240080896 times.
2263709696 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2304 {
2305
2/2
✓ Branch 0 taken 4689080 times.
✓ Branch 1 taken 235391816 times.
240080896 switch(i)
2306 {
2307 case itype_bomb:
2308 case itype_sbomb:
2309 case itype_clock:
2310 case itype_key:
2311 case itype_lkey:
2312 case itype_map:
2313 case itype_compass:
2314 case itype_bosskey:
2315 case itype_magiccontainer:
2316 case itype_triforcepiece:
2317 4689080 continue; //already handled
2318 }
2319 235391816 }
2320 2259020616 int32_t itemid = current_item_id(i,false);
2321
2/2
✓ Branch 0 taken 2254599308 times.
✓ Branch 1 taken 4421308 times.
2259020616 if(i == itype_shield)
2322 4421308 itemid = getCurrentShield(false);
2323
2324
4/4
✓ Branch 0 taken 115677585 times.
✓ Branch 1 taken 2143343031 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 115677584 times.
2259020616 if(itemid < 0 || !checkbunny(itemid))
2325 2143343032 continue;
2326
2327 115677584 itemdata const& itm = itemsbuf[itemid];
2328
2329
2/2
✓ Branch 0 taken 111976863 times.
✓ Branch 1 taken 3700721 times.
115677584 switch(itm.type)
2330 {
2331 case itype_shield:
2332
1/2
✓ Branch 0 taken 3700721 times.
✗ Branch 1 not taken.
3700721 if(itm.flags & item_flag9) //active shield
2333 {
2334 if(!usingActiveShield(itemid))
2335 {
2336 tile+=itm.misc6; //'Inactive PTM'
2337 continue;
2338 }
2339 }
2340 3700721 break;
2341 }
2342
2343 115677584 tile+=itm.ltm;
2344 115677584 }
2345
2346 4421308 tilemod_cache_value = tile;
2347 4421308 tilemod_cache_state = state;
2348 4421308 return tile;
2349 12964164 }
2350
2351 12964164 int32_t bunny_tile_mod()
2352 {
2353
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12962294 times.
12964164 if(Hero.BunnyClock())
2354 {
2355 1870 return game->get_bunny_ltm();
2356 }
2357 12962294 return 0;
2358 12964164 }
2359
2360 // Hints are drawn on a separate layer to combo reveals.
2361 // TODO: move out of zc_sys.cpp, weird place for this code.
2362 20058 void draw_lens_under(BITMAP *dest, bool layer)
2363 {
2364 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2365 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2366 //Lens flag 3: Don't show armos/chest/dive items
2367 //Lens flag 4: Show Raft Paths
2368 //Lens flag 5: Show Invisible Enemies
2369
4/4
✓ Branch 0 taken 19602 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 9801 times.
✓ Branch 3 taken 9801 times.
20058 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2370
2371 20058 int32_t strike_hint_table[11]=
2372 {
2373 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2374 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2375 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2376 };
2377
2378 {
2379 20058 int32_t blink_rate=flash_reduction_enabled()?6:1;
2380 20058 int32_t tempitem, tempweapon=0;
2381 20058 strike_hint=strike_hint_table[strike_hint_counter];
2382
2383
2/2
✓ Branch 0 taken 19459 times.
✓ Branch 1 taken 599 times.
20058 if(strike_hint_timer>32)
2384 {
2385 599 strike_hint_timer=0;
2386 599 strike_hint_counter=((strike_hint_counter+1)%11);
2387 599 }
2388
2389 20058 ++strike_hint_timer;
2390
2391 3550266 for_every_visible_rpos_layer0([&](const rpos_handle_t& rpos_handle) {
2392 3530208 mapscr* scr = rpos_handle.scr;
2393 7306676 auto [x, y] = rpos_handle.xy();
2394 7060416 y += playing_field_offset;
2395
2396 3530208 int32_t tempitemx=-16, tempitemy=-16;
2397 3530208 int32_t tempweaponx=-16, tempweapony=-16;
2398
2399
2/2
✓ Branch 0 taken 7060416 times.
✓ Branch 1 taken 3530208 times.
10590624 for(int32_t iter=0; iter<2; ++iter)
2400 {
2401 7060416 int32_t checkflag=0;
2402
2403
2/2
✓ Branch 0 taken 3530208 times.
✓ Branch 1 taken 3530208 times.
7060416 if(iter==0)
2404 {
2405 3530208 checkflag = rpos_handle.cflag();
2406 3530208 }
2407 else
2408 {
2409 3530208 checkflag = rpos_handle.sflag();
2410 }
2411
2412
2/2
✓ Branch 0 taken 7059318 times.
✓ Branch 1 taken 1098 times.
7060416 if(checkflag==mfSTRIKE)
2413 {
2414
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2415 {
2416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSTRIKE],scr->secretcset[sSTRIKE]);
2417 906 }
2418 else
2419 {
2420 192 checkflag = strike_hint;
2421 }
2422 1098 }
2423
2424
21/36
✓ Branch 0 taken 6911766 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7060416 switch(checkflag)
2425 {
2426 case 0:
2427 case mfZELDA:
2428 case mfPUSHED:
2429 case mfENEMY0:
2430 case mfENEMY1:
2431 case mfENEMY2:
2432 case mfENEMY3:
2433 case mfENEMY4:
2434 case mfENEMY5:
2435 case mfENEMY6:
2436 case mfENEMY7:
2437 case mfENEMY8:
2438 case mfENEMY9:
2439 case mfSINGLE:
2440 case mfSINGLE16:
2441 case mfNOENEMY:
2442 case mfTRAP_H:
2443 case mfTRAP_V:
2444 case mfTRAP_4:
2445 case mfTRAP_LR:
2446 case mfTRAP_UD:
2447 case mfNOGROUNDENEMY:
2448 case mfNOBLOCKS:
2449 case mfSCRIPT1:
2450 case mfSCRIPT2:
2451 case mfSCRIPT3:
2452 case mfSCRIPT4:
2453 case mfSCRIPT5:
2454 case mfSCRIPT6:
2455 case mfSCRIPT7:
2456 case mfSCRIPT8:
2457 case mfSCRIPT9:
2458 case mfSCRIPT10:
2459 case mfSCRIPT11:
2460 case mfSCRIPT12:
2461 case mfSCRIPT13:
2462 case mfSCRIPT14:
2463 case mfSCRIPT15:
2464 case mfSCRIPT16:
2465 case mfSCRIPT17:
2466 case mfSCRIPT18:
2467 case mfSCRIPT19:
2468 case mfSCRIPT20:
2469 case mfPITHOLE:
2470 case mfPITFALLFLOOR:
2471 case mfLAVA:
2472 case mfICE:
2473 case mfICEDAMAGE:
2474 case mfDAMAGE1:
2475 case mfDAMAGE2:
2476 case mfDAMAGE4:
2477 case mfDAMAGE8:
2478 case mfDAMAGE16:
2479 case mfDAMAGE32:
2480 case mfFREEZEALL:
2481 case mfFREZEALLANSFFCS:
2482 case mfFREEZEFFCSOLY:
2483 case mfSCRITPTW1TRIG:
2484 case mfSCRITPTW2TRIG:
2485 case mfSCRITPTW3TRIG:
2486 case mfSCRITPTW4TRIG:
2487 case mfSCRITPTW5TRIG:
2488 case mfSCRITPTW6TRIG:
2489 case mfSCRITPTW7TRIG:
2490 case mfSCRITPTW8TRIG:
2491 case mfSCRITPTW9TRIG:
2492 case mfSCRITPTW10TRIG:
2493 case mfTROWEL:
2494 case mfTROWELNEXT:
2495 case mfTROWELSPECIALITEM:
2496 case mfSLASHPOT:
2497 case mfLIFTPOT:
2498 case mfLIFTORSLASH:
2499 case mfLIFTROCK:
2500 case mfLIFTROCKHEAVY:
2501 case mfDROPITEM:
2502 case mfSPECIALITEM:
2503 case mfDROPKEY:
2504 case mfDROPLKEY:
2505 case mfDROPCOMPASS:
2506 case mfDROPMAP:
2507 case mfDROPBOSSKEY:
2508 case mfSPAWNNPC:
2509 case mfSWITCHHOOK:
2510 case mfSIDEVIEWLADDER:
2511 case mfSIDEVIEWPLATFORM:
2512 case mfNOENEMYSPAWN:
2513 case mfENEMYALL:
2514 case mfNOMIRROR:
2515 case mfUNSAFEGROUND:
2516 case mf168:
2517 case mf169:
2518 case mf170:
2519 case mf171:
2520 case mf172:
2521 case mf173:
2522 case mf174:
2523 case mf175:
2524 case mf176:
2525 case mf177:
2526 case mf178:
2527 case mf179:
2528 case mf180:
2529 case mf181:
2530 case mf182:
2531 case mf183:
2532 case mf184:
2533 case mf185:
2534 case mf186:
2535 case mf187:
2536 case mf188:
2537 case mf189:
2538 case mf190:
2539 case mf191:
2540 case mf192:
2541 case mf193:
2542 case mf194:
2543 case mf195:
2544 case mf196:
2545 case mf197:
2546 case mf198:
2547 case mf199:
2548 case mf200:
2549 case mf201:
2550 case mf202:
2551 case mf203:
2552 case mf204:
2553 case mf205:
2554 case mf206:
2555 case mf207:
2556 case mf208:
2557 case mf209:
2558 case mf210:
2559 case mf211:
2560 case mf212:
2561 case mf213:
2562 case mf214:
2563 case mf215:
2564 case mf216:
2565 case mf217:
2566 case mf218:
2567 case mf219:
2568 case mf220:
2569 case mf221:
2570 case mf222:
2571 case mf223:
2572 case mf224:
2573 case mf225:
2574 case mf226:
2575 case mf227:
2576 case mf228:
2577 case mf229:
2578 case mf230:
2579 case mf231:
2580 case mf232:
2581 case mf233:
2582 case mf234:
2583 case mf235:
2584 case mf236:
2585 case mf237:
2586 case mf238:
2587 case mf239:
2588 case mf240:
2589 case mf241:
2590 case mf242:
2591 case mf243:
2592 case mf244:
2593 case mf245:
2594 case mf246:
2595 case mf247:
2596 case mf248:
2597 case mf249:
2598 case mf250:
2599 case mf251:
2600 case mf252:
2601 case mf253:
2602 case mf254:
2603 case mfEXTENDED:
2604 6911766 break;
2605
2606 case mfPUSHUD:
2607 case mfPUSHLR:
2608 case mfPUSH4:
2609 case mfPUSHU:
2610 case mfPUSHD:
2611 case mfPUSHL:
2612 case mfPUSHR:
2613 case mfPUSHUDNS:
2614 case mfPUSHLRNS:
2615 case mfPUSH4NS:
2616 case mfPUSHUNS:
2617 case mfPUSHDNS:
2618 case mfPUSHLNS:
2619 case mfPUSHRNS:
2620 case mfPUSHUDINS:
2621 case mfPUSHLRINS:
2622 case mfPUSH4INS:
2623 case mfPUSHUINS:
2624 case mfPUSHDINS:
2625 case mfPUSHLINS:
2626 case mfPUSHRINS:
2627
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2628
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2629 {
2630 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->undercombo,scr->undercset);
2631 }
2632
2633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2634
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2635 {
2636
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2637 {
2638
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch (rpos_handle.ctype())
2639 {
2640 case cPUSH_HEAVY:
2641 case cPUSH_HW:
2642 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2643 144 tempitemx=x, tempitemy=y;
2644
2645
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(tempitem>-1)
2646 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2647
2648 72 break;
2649
2650 case cPUSH_HEAVY2:
2651 case cPUSH_HW2:
2652 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2653 126 tempitemx=x, tempitemy=y;
2654
2655
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if(tempitem>-1)
2656 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2657
2658 63 break;
2659 }
2660 1032 }
2661 2520 }
2662
2663 3258 break;
2664
2665 case mfWHISTLE:
2666
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2667 {
2668 tempitem=getItemID(itemsbuf,itype_whistle,1);
2669
2670 if(tempitem<0) break;
2671
2672 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2673 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2674 {
2675 tempitemx=x;
2676 tempitemy=y;
2677 }
2678
2679 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2680 }
2681
2682 2418 break;
2683
2684 //Why is this here?
2685 case mfFAIRY:
2686 case mfMAGICFAIRY:
2687 case mfALLFAIRY:
2688 if(hints)
2689 {
2690 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2691
2692 if(tempitem < 0) break;
2693
2694 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2695 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2696 {
2697 tempitemx=x;
2698 tempitemy=y;
2699 }
2700
2701 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2702 }
2703
2704 break;
2705
2706 case mfANYFIRE:
2707
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2708 {
2709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBCANDLE],scr->secretcset[sBCANDLE]);
2710 252 }
2711 else
2712 {
2713 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2714
2715
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2716
2717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2718
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2719 {
2720 189 tempitemx=x;
2721 189 tempitemy=y;
2722 189 }
2723
2724 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2725 }
2726
2727 504 break;
2728
2729 case mfSTRONGFIRE:
2730 if(!hints)
2731 {
2732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sRCANDLE],scr->secretcset[sRCANDLE]);
2733 }
2734 else
2735 {
2736 tempitem=getItemID(itemsbuf,itype_candle,2);
2737
2738 if(tempitem<0) break;
2739
2740 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2741 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2742 {
2743 tempitemx=x;
2744 tempitemy=y;
2745 }
2746
2747 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2748 }
2749
2750 break;
2751
2752 case mfMAGICFIRE:
2753 if(!hints)
2754 {
2755 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDFIRE],scr->secretcset[sWANDFIRE]);
2756 }
2757 else
2758 {
2759 tempitem=getItemID(itemsbuf,itype_wand,1);
2760
2761 if(tempitem<0) break;
2762
2763 tempweapon=wFire;
2764
2765 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2766 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2767 {
2768 tempitemx=x;
2769 tempitemy=y;
2770 }
2771 else
2772 {
2773 tempweaponx=x;
2774 tempweapony=y;
2775 }
2776
2777 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2778 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2779 }
2780
2781 break;
2782
2783 case mfDIVINEFIRE:
2784 if(!hints)
2785 {
2786 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sDIVINEFIRE],scr->secretcset[sDIVINEFIRE]);
2787 }
2788 else
2789 {
2790 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2791
2792 if(tempitem<0) break;
2793
2794 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2795 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2796 {
2797 tempitemx=x;
2798 tempitemy=y;
2799 }
2800
2801 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2802 }
2803
2804 break;
2805
2806 case mfARROW:
2807
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2808 {
2809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sARROW],scr->secretcset[sARROW]);
2810 732 }
2811 else
2812 {
2813 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2814
2815
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2816
2817
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2818
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2819 {
2820 61 tempitemx=x;
2821 61 tempitemy=y;
2822 61 }
2823
2824 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2825 }
2826
2827 814 break;
2828
2829 case mfSARROW:
2830 if(!hints)
2831 {
2832 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSARROW],scr->secretcset[sSARROW]);
2833 }
2834 else
2835 {
2836 tempitem=getItemID(itemsbuf,itype_arrow,2);
2837
2838 if(tempitem<0) break;
2839
2840 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2841 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2842 {
2843 tempitemx=x;
2844 tempitemy=y;
2845 }
2846
2847 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2848 }
2849
2850 break;
2851
2852 case mfGARROW:
2853 if(!hints)
2854 {
2855 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sGARROW],scr->secretcset[sGARROW]);
2856 }
2857 else
2858 {
2859 tempitem=getItemID(itemsbuf,itype_arrow,3);
2860
2861 if(tempitem<0) break;
2862
2863 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2864 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2865 {
2866 tempitemx=x;
2867 tempitemy=y;
2868 }
2869
2870 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2871 }
2872
2873 break;
2874
2875 case mfBOMB:
2876
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2877 {
2878
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBOMB],scr->secretcset[sBOMB]);
2879 76 }
2880 else
2881 {
2882 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2883 17 tempweapon = wLitBomb;
2884
2885 //if (tempitem<0) break;
2886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2887
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2888 {
2889 12 tempweaponx=x;
2890 12 tempweapony=y;
2891 12 }
2892
2893 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2894 }
2895
2896 93 break;
2897
2898 case mfSBOMB:
2899
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2900 {
2901
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSBOMB],scr->secretcset[sSBOMB]);
2902 48 }
2903 else
2904 {
2905 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2906 //if (tempitem<0) break;
2907 48 tempweapon = wLitSBomb;
2908
2909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2910
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2911 {
2912 36 tempweaponx=x;
2913 36 tempweapony=y;
2914 36 }
2915
2916 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2917 }
2918
2919 96 break;
2920
2921 case mfARMOS_SECRET:
2922
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2923 {
2924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2925 36 putcombo(dest,x,y,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
2926 12 }
2927 24 break;
2928
2929 case mfBRANG:
2930
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2931 {
2932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2933 60 putcombo(dest,x,y,scr->secretcombo[sBRANG],scr->secretcset[sBRANG]);
2934 20 }
2935 else
2936 {
2937 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2938
2939
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2940
2941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2942
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2943 {
2944 4 tempitemx=x;
2945 4 tempitemy=y;
2946 4 }
2947
2948 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2949 }
2950
2951 25 break;
2952
2953 case mfMBRANG:
2954 if(!hints)
2955 {
2956 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMBRANG],scr->secretcset[sMBRANG]);
2957 }
2958 else
2959 {
2960 tempitem=getItemID(itemsbuf,itype_brang,2);
2961
2962 if(tempitem<0) break;
2963
2964 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2965 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2966 {
2967 tempitemx=x;
2968 tempitemy=y;
2969 }
2970
2971 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2972 }
2973
2974 break;
2975
2976 case mfFBRANG:
2977 if(!hints)
2978 {
2979 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sFBRANG],scr->secretcset[sFBRANG]);
2980 }
2981 else
2982 {
2983 tempitem=getItemID(itemsbuf,itype_brang,3);
2984
2985 if(tempitem<0) break;
2986
2987 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2988 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2989 {
2990 tempitemx=x;
2991 tempitemy=y;
2992 }
2993
2994 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2995 }
2996
2997 break;
2998
2999 case mfWANDMAGIC:
3000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
3001 {
3002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDMAGIC],scr->secretcset[sWANDMAGIC]);
3003 138 }
3004 else
3005 {
3006 tempitem=getItemID(itemsbuf,itype_wand,1);
3007
3008 if(tempitem<0) break;
3009
3010 tempweapon=itemsbuf[tempitem].wpn3;
3011
3012 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3013 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3014 {
3015 tempitemx=x;
3016 tempitemy=y;
3017 }
3018 else
3019 {
3020 tempweaponx=x;
3021 tempweapony=y;
3022 --lens_hint_weapon[wMagic][4];
3023
3024 if(lens_hint_weapon[wMagic][4]<-8)
3025 {
3026 lens_hint_weapon[wMagic][4]=8;
3027 }
3028 }
3029
3030 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3031 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3032 }
3033
3034 138 break;
3035
3036 case mfREFMAGIC:
3037
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3038 {
3039 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFMAGIC],scr->secretcset[sREFMAGIC]);
3040 }
3041 else
3042 {
3043 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3044
3045
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3046
3047 16 tempweapon=ewMagic;
3048
3049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3050
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3051 {
3052 13 tempitemx=x;
3053 13 tempitemy=y;
3054 13 }
3055 else
3056 {
3057 3 tempweaponx=x;
3058 3 tempweapony=y;
3059
3060
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3061 {
3062 1 --lens_hint_weapon[ewMagic][4];
3063 1 }
3064 else
3065 {
3066 2 ++lens_hint_weapon[ewMagic][4];
3067 }
3068
3069
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3070 {
3071 lens_hint_weapon[ewMagic][2]=up;
3072 }
3073
3074
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3075 {
3076 2 lens_hint_weapon[ewMagic][2]=down;
3077 2 }
3078 }
3079
3080 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3081 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3082 }
3083
3084 16 break;
3085
3086 case mfREFFIREBALL:
3087
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3088 {
3089 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFFIREBALL],scr->secretcset[sREFFIREBALL]);
3090 }
3091 else
3092 {
3093 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3094
3095
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3096
3097 16 tempweapon=ewFireball;
3098
3099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3100
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3101 {
3102 12 tempitemx=x;
3103 12 tempitemy=y;
3104 12 tempweaponx=x;
3105 12 tempweapony=y;
3106 12 ++lens_hint_weapon[ewFireball][3];
3107
3108
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3109 {
3110 1 lens_hint_weapon[ewFireball][3]=-8;
3111 1 lens_hint_weapon[ewFireball][4]=8;
3112 1 }
3113
3114
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3115 {
3116 8 ++lens_hint_weapon[ewFireball][4];
3117 8 }
3118 else
3119 {
3120 4 --lens_hint_weapon[ewFireball][4];
3121 }
3122 12 }
3123
3124 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3125 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3126 }
3127
3128 16 break;
3129
3130 case mfSWORD:
3131
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3132 {
3133 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORD],scr->secretcset[sSWORD]);
3134 }
3135 else
3136 {
3137 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3138
3139
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3140
3141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3142
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3143 {
3144 5 tempitemx=x;
3145 5 tempitemy=y;
3146 5 }
3147
3148 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3149 }
3150
3151 7 break;
3152
3153 case mfWSWORD:
3154 if(!hints)
3155 {
3156 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORD],scr->secretcset[sWSWORD]);
3157 }
3158 else
3159 {
3160 tempitem=getItemID(itemsbuf,itype_sword,2);
3161
3162 if(tempitem<0) break;
3163
3164 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3165 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3166 {
3167 tempitemx=x;
3168 tempitemy=y;
3169 }
3170
3171 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3172 }
3173
3174 break;
3175
3176 case mfMSWORD:
3177 if(!hints)
3178 {
3179 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORD],scr->secretcset[sMSWORD]);
3180 }
3181 else
3182 {
3183 tempitem=getItemID(itemsbuf,itype_sword,3);
3184
3185 if(tempitem<0) break;
3186
3187 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3188 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3189 {
3190 tempitemx=x;
3191 tempitemy=y;
3192 }
3193
3194 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3195 }
3196
3197 break;
3198
3199 case mfXSWORD:
3200 if(!hints)
3201 {
3202 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORD],scr->secretcset[sXSWORD]);
3203 }
3204 else
3205 {
3206 tempitem=getItemID(itemsbuf,itype_sword,4);
3207
3208 if(tempitem<0) break;
3209
3210 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3211 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3212 {
3213 tempitemx=x;
3214 tempitemy=y;
3215 }
3216
3217 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3218 }
3219
3220 break;
3221
3222 case mfSWORDBEAM:
3223
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3224 {
3225 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORDBEAM],scr->secretcset[sSWORDBEAM]);
3226 }
3227 else
3228 {
3229 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3230
3231
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3232
3233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3234
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3235 {
3236 11 tempitemx=x;
3237 11 tempitemy=y;
3238 11 }
3239
3240 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3241 }
3242
3243 16 break;
3244
3245 case mfWSWORDBEAM:
3246 if(!hints)
3247 {
3248 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORDBEAM],scr->secretcset[sWSWORDBEAM]);
3249 }
3250 else
3251 {
3252 tempitem=getItemID(itemsbuf,itype_sword,2);
3253
3254 if(tempitem<0) break;
3255
3256 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3257 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3258 {
3259 tempitemx=x;
3260 tempitemy=y;
3261 }
3262
3263 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3264 }
3265
3266 break;
3267
3268 case mfMSWORDBEAM:
3269 if(!hints)
3270 {
3271 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORDBEAM],scr->secretcset[sMSWORDBEAM]);
3272 }
3273 else
3274 {
3275 tempitem=getItemID(itemsbuf,itype_sword,3);
3276
3277 if(tempitem<0) break;
3278
3279 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3280 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3281 {
3282 tempitemx=x;
3283 tempitemy=y;
3284 }
3285
3286 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3287 }
3288
3289 break;
3290
3291 case mfXSWORDBEAM:
3292 if(!hints)
3293 {
3294 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORDBEAM],scr->secretcset[sXSWORDBEAM]);
3295 }
3296 else
3297 {
3298 tempitem=getItemID(itemsbuf,itype_sword,4);
3299
3300 if(tempitem<0) break;
3301
3302 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3303 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3304 {
3305 tempitemx=x;
3306 tempitemy=y;
3307 }
3308
3309 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3310 }
3311
3312 break;
3313
3314 case mfHOOKSHOT:
3315
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3316 {
3317 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHOOKSHOT],scr->secretcset[sHOOKSHOT]);
3318 }
3319 else
3320 {
3321 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3322
3323
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3324
3325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3326
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3327 {
3328 12 tempitemx=x;
3329 12 tempitemy=y;
3330 12 }
3331
3332 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3333 }
3334
3335 17 break;
3336
3337 case mfWAND:
3338
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3339 {
3340 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWAND],scr->secretcset[sWAND]);
3341 }
3342 else
3343 {
3344 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3345
3346
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3347
3348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3349
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3350 {
3351 28 tempitemx=x;
3352 28 tempitemy=y;
3353 28 }
3354
3355 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3356 }
3357
3358 35 break;
3359
3360 case mfHAMMER:
3361
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3362 {
3363 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHAMMER],scr->secretcset[sHAMMER]);
3364 }
3365 else
3366 {
3367 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3368
3369
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3370
3371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3372
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3373 {
3374 13 tempitemx=x;
3375 13 tempitemy=y;
3376 13 }
3377
3378 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3379 }
3380
3381 17 break;
3382
3383 case mfARMOS_ITEM:
3384 case mfDIVE_ITEM:
3385 {
3386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
2602 int flag = (cur_screen < 128 && get_qr(qr_ITEMPICKUPSETSBELOW)) ? mITEM : mSPECIALITEM;
3387
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2602 times.
2602 if((!getmapflag(scr, flag) || (scr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3388 {
3389 7806 putitem2(dest,x,y,scr->catchall, lens_hint_item[scr->catchall][0], lens_hint_item[scr->catchall][1], 0);
3390 2602 }
3391 2602 break;
3392 }
3393
3394 case 16:
3395 case 17:
3396 case 18:
3397 case 19:
3398 case 20:
3399 case 21:
3400 case 22:
3401 case 23:
3402 case 24:
3403 case 25:
3404 case 26:
3405 case 27:
3406 case 28:
3407 case 29:
3408 case 30:
3409 case 31:
3410
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3412 323670 putcombo(dest,x,y,scr->secretcombo[checkflag-16+4],scr->secretcset[checkflag-16+4]);
3413
3414 108898 break;
3415 case mfSECRETSNEXT:
3416 if(!hints)
3417 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3418 putcombo(dest,x,y,rpos_handle.data()+1,rpos_handle.cset());
3419
3420 break;
3421
3422 case mfSTRIKE:
3423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3424 {
3425 906 goto special;
3426 }
3427 else
3428 {
3429 break;
3430 }
3431
3432 28750 default: goto special;
3433
3434 special:
3435
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3436 {
3437
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3438 {
3439 24770 rectfill(dest,x,y,x+15,y+15,WHITE);
3440 4954 }
3441 6604 }
3442
3443 29656 break;
3444 }
3445 7060416 }
3446 3530208 });
3447
3448 40116 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3449 90824 auto [offx, offy] = translate_screen_coordinates_to_world(scr->screen);
3450
3451 40116 offx -= viewport.x;
3452 40116 offy -= viewport.y;
3453 40116 offy += playing_field_offset;
3454
3455
2/2
✓ Branch 0 taken 10029 times.
✓ Branch 1 taken 10029 times.
20058 if (layer)
3456 {
3457
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 359 times.
10029 if (scr->door[0]==dWALK)
3458 1795 rectfill(dest, 120+offx, 16+offy, 135+offx, 31+offy, WHITE);
3459
3460
2/2
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 423 times.
10029 if (scr->door[1]==dWALK)
3461 2115 rectfill(dest, 120+offx, 144+offy, 135+offx, 159+offy, WHITE);
3462
3463
2/2
✓ Branch 0 taken 9447 times.
✓ Branch 1 taken 582 times.
10029 if (scr->door[2]==dWALK)
3464 2910 rectfill(dest, 16+offx, 80+offy, 31+offx, 95+offy, WHITE);
3465
3466
2/2
✓ Branch 0 taken 9405 times.
✓ Branch 1 taken 624 times.
10029 if (scr->door[3]==dWALK)
3467 3120 rectfill(dest, 224+offx, 80+offy, 239+offx, 95+offy, WHITE);
3468
3469
2/2
✓ Branch 0 taken 9986 times.
✓ Branch 1 taken 43 times.
10029 if (scr->door[0]==dBOMB)
3470 {
3471 129 showbombeddoor(scr, dest, 0, offx, offy);
3472 43 }
3473
3474
2/2
✓ Branch 0 taken 9990 times.
✓ Branch 1 taken 39 times.
10029 if (scr->door[1]==dBOMB)
3475 {
3476 117 showbombeddoor(scr, dest, 1, offx, offy);
3477 39 }
3478
3479
2/2
✓ Branch 0 taken 10023 times.
✓ Branch 1 taken 6 times.
10029 if (scr->door[2]==dBOMB)
3480 {
3481 18 showbombeddoor(scr, dest, 2, offx, offy);
3482 6 }
3483
3484
2/2
✓ Branch 0 taken 9992 times.
✓ Branch 1 taken 37 times.
10029 if (scr->door[3]==dBOMB)
3485 {
3486 111 showbombeddoor(scr, dest, 3, offx, offy);
3487 37 }
3488 10029 }
3489
3490
3/4
✓ Branch 0 taken 18024 times.
✓ Branch 1 taken 2034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18024 times.
20058 if (scr->stairx || scr->stairy)
3491 {
3492
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if (!hints)
3493 {
3494
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if (!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3495 3369 putcombo(dest,scr->stairx+offx,scr->stairy+offy,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
3496 1123 }
3497 else
3498 {
3499
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(scr->flags&fWHISTLE)
3500 {
3501 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3502 48 int32_t tempitemx=-16+offx;
3503 48 int32_t tempitemy=-16+offy-playing_field_offset;
3504
3505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3506
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3507 {
3508 48 tempitemx=scr->stairx+offx;
3509 48 tempitemy=scr->stairy+offy;
3510 24 }
3511
3512 48 putitem2(dest, tempitemx, tempitemy, tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3513 48 }
3514 }
3515 2034 }
3516 20058 });
3517 }
3518 20058 }
3519
3520 9690 void draw_lens_over()
3521 {
3522 9690 int w = 288;
3523 9690 int h = 240;
3524
3525
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9672 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
9690 static BITMAP *lens_scr = create_bitmap_ex(8,2*w,2*h);
3526 static int32_t last_width = -1;
3527 9690 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3528
3529 // Only redraw the circle if the size has changed
3530
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 20 times.
9690 if (width != last_width)
3531 {
3532 20 clear_to_color(lens_scr, BLACK);
3533 20 circlefill(lens_scr, w, h, width, 0);
3534 20 circle(lens_scr, w, h, width+2, 0);
3535 20 circle(lens_scr, w, h, width+5, 0);
3536 20 last_width=width;
3537 20 }
3538
3539 9690 masked_blit(lens_scr, framebuf, w-(HeroX()+8)+viewport.x, h-(HeroY()+8)+viewport.y, 0, playing_field_offset, 256, viewport.h);
3540 9690 do_primitives(framebuf, SPLAYER_LENS_OVER);
3541 9690 }
3542
3543 37080264 static void update_bmp_size(BITMAP** bmp_ptr, int w, int h)
3544 {
3545 37080264 BITMAP* bmp = *bmp_ptr;
3546
3/4
✓ Branch 0 taken 37080264 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37080258 times.
✓ Branch 3 taken 6 times.
37080264 if (bmp->w == w && bmp->h == h)
3547 37080258 return;
3548
3549 6 int depth = bitmap_color_depth(bmp);
3550 6 destroy_bitmap(bmp);
3551 6 *bmp_ptr = create_bitmap_ex(depth, w, h);
3552 37080264 }
3553
3554 32028 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3555 {
3556
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 32022 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
32028 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3557 32028 update_bmp_size(&wavebuf, 288, 240 - original_playing_field_offset);
3558
3559 32028 clear_to_color(wavebuf, BLACK);
3560 32028 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,framebuf->h-original_playing_field_offset);
3561
3562 int32_t ofs;
3563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32028 times.
32028 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3564
4/6
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
✓ Branch 4 taken 606 times.
✓ Branch 5 taken 31422 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3565 32028 int32_t amp2 = viewport.visible_height(show_bottom_8px);
3566
2/4
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3567 32028 int32_t i=frame%amp2;
3568
3569
2/2
✓ Branch 0 taken 5382552 times.
✓ Branch 1 taken 32028 times.
5414580 for(int32_t j=0; j<viewport.visible_height(show_bottom_8px); j++)
3570 {
3571
3/4
✓ Branch 0 taken 2691276 times.
✓ Branch 1 taken 2691276 times.
✓ Branch 2 taken 2691276 times.
✗ Branch 3 not taken.
5382552 if(j&1 && interpol)
3572 {
3573 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3574 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3575 }
3576 else
3577 {
3578 5382552 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3579 }
3580
3581
1/2
✓ Branch 0 taken 5382552 times.
✗ Branch 1 not taken.
5382552 if(ofs)
3582 {
3583
2/2
✓ Branch 0 taken 1377933312 times.
✓ Branch 1 taken 5382552 times.
1383315864 for(int32_t k=0; k<256; k++)
3584 {
3585 1377933312 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3586 1377933312 }
3587 5382552 }
3588 5382552 }
3589 32028 }
3590
3591 28272 void draw_fuzzy(int32_t fuzz)
3592 // draws from right half of scrollbuf to framebuf
3593 {
3594 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3595 byte *start, *si, *di;
3596
3597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28272 times.
28272 if(fuzz<1)
3598 fuzz = 1;
3599
3600 28272 xstep = 128%fuzz;
3601
3602
2/2
✓ Branch 0 taken 5890 times.
✓ Branch 1 taken 22382 times.
28272 if(xstep > 0)
3603 22382 xstep = fuzz-xstep;
3604
3605 28272 ystep = 112%fuzz;
3606
3607
2/2
✓ Branch 0 taken 8246 times.
✓ Branch 1 taken 20026 times.
28272 if(ystep > 0)
3608 20026 ystep = fuzz-ystep;
3609
3610 28272 firsty = 1;
3611
3612
2/2
✓ Branch 0 taken 28272 times.
✓ Branch 1 taken 1020148 times.
1048420 for(y=0; y<framebuf->h;)
3613 {
3614 1020148 start = &(scrollbuf_old->line[y][256]);
3615
3616
4/4
✓ Branch 0 taken 1006012 times.
✓ Branch 1 taken 6347064 times.
✓ Branch 2 taken 6332928 times.
✓ Branch 3 taken 1020148 times.
7353076 for(dy=0; dy<ystep && dy+y<framebuf->h; dy++)
3617 {
3618 6332928 si = start;
3619 6332928 di = &(framebuf->line[y+dy][0]);
3620 6332928 i = xstep;
3621 6332928 firstx = 1;
3622
3623
2/2
✓ Branch 0 taken 1621229568 times.
✓ Branch 1 taken 6332928 times.
1627562496 for(dx=0; dx<framebuf->w; dx++)
3624 {
3625 1621229568 *(di++) = *si;
3626
3627
2/2
✓ Branch 0 taken 1366065344 times.
✓ Branch 1 taken 255164224 times.
1621229568 if(++i >= fuzz)
3628 {
3629
2/2
✓ Branch 0 taken 248831296 times.
✓ Branch 1 taken 6332928 times.
255164224 if(!firstx)
3630 248831296 si += fuzz;
3631 else
3632 {
3633 6332928 si += fuzz-xstep;
3634 6332928 firstx = 0;
3635 }
3636
3637 255164224 i = 0;
3638 255164224 }
3639 1621229568 }
3640 6332928 }
3641
3642
2/2
✓ Branch 0 taken 991876 times.
✓ Branch 1 taken 28272 times.
1020148 if(!firsty)
3643 991876 y += fuzz;
3644 else
3645 {
3646 28272 y += ystep;
3647 28272 ystep = fuzz;
3648 28272 firsty = 0;
3649 }
3650 }
3651 28272 }
3652
3653 18524118 void updatescr(bool allowwavy)
3654 {
3655
4/6
✓ Branch 0 taken 314 times.
✓ Branch 1 taken 18523804 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 314 times.
✓ Branch 4 taken 314 times.
✗ Branch 5 not taken.
18524118 static BITMAP *wavybuf = create_bitmap_ex(8, framebuf->w, framebuf->h);
3656
4/6
✓ Branch 0 taken 314 times.
✓ Branch 1 taken 18523804 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 314 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 314 times.
18524118 static BITMAP *panorama = create_bitmap_ex(8, framebuf->w, framebuf->h);
3657 18524118 update_bmp_size(&wavybuf, framebuf->w, framebuf->h);
3658 18524118 update_bmp_size(&panorama, framebuf->w, framebuf->h);
3659
3660
2/2
✓ Branch 0 taken 18496017 times.
✓ Branch 1 taken 28101 times.
18524118 if(walk_through_walls)
3661 {
3662 28101 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3663 28101 }
3664
3665
1/2
✓ Branch 0 taken 18524118 times.
✗ Branch 1 not taken.
18524118 if(Showpal)
3666 dump_pal(framebuf);
3667
3668
2/2
✓ Branch 0 taken 18008436 times.
✓ Branch 1 taken 515682 times.
18524118 if(!Playing)
3669 515682 black_opening_count=0;
3670
3671
2/2
✓ Branch 0 taken 18355207 times.
✓ Branch 1 taken 168911 times.
18524118 if(black_opening_count<0) //shape is opening up
3672 {
3673 168911 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3674
3675
2/4
✓ Branch 0 taken 168911 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 168911 times.
168911 if(Advance||(!Paused))
3676 {
3677 168911 ++black_opening_count;
3678 168911 }
3679 168911 }
3680
2/2
✓ Branch 0 taken 18306433 times.
✓ Branch 1 taken 48774 times.
18355207 else if(black_opening_count>0) //shape is closing
3681 {
3682 48774 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3683
3684
2/4
✓ Branch 0 taken 48774 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48774 times.
48774 if(Advance||(!Paused))
3685 {
3686 48774 --black_opening_count;
3687 48774 }
3688 48774 }
3689
3690
3/4
✓ Branch 0 taken 18309731 times.
✓ Branch 1 taken 214387 times.
✓ Branch 2 taken 18309731 times.
✗ Branch 3 not taken.
18524118 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3691 {
3692 black_opening_shape = bosCIRCLE;
3693 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3694 refreshTints();
3695 refreshpal=true;
3696 }
3697
3698
2/2
✓ Branch 0 taken 17891133 times.
✓ Branch 1 taken 632985 times.
18524118 if(refreshpal)
3699 {
3700 632985 refreshpal=false;
3701 632985 RAMpal[253] = _RGB(0,0,0);
3702 632985 RAMpal[254] = _RGB(255,255,255);
3703 632985 hw_palette = &RAMpal;
3704 632985 update_hw_pal = true;
3705 632985 refresh_rgb_tables();
3706 632985 }
3707
3708 18524118 bool clearwavy = (wavy <= 0);
3709
3710
2/2
✓ Branch 0 taken 8572 times.
✓ Branch 1 taken 18515546 times.
18524118 if(wavy <= 0)
3711 {
3712 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3713 18515546 wavy = (DMaps[cur_dmap].flags&dmfWAVY ? 4 : 0);
3714 18515546 }
3715
3716 18524118 blit(framebuf, wavybuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3717
3718
6/6
✓ Branch 0 taken 32278 times.
✓ Branch 1 taken 18491840 times.
✓ Branch 2 taken 32156 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 32028 times.
18524118 if(wavy && Playing && allowwavy)
3719 {
3720 32028 draw_wavy(framebuf, wavybuf, wavy,false);
3721 32028 }
3722
3723
2/2
✓ Branch 0 taken 18515546 times.
✓ Branch 1 taken 8572 times.
18524118 if(clearwavy)
3724 18515546 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3725
2/4
✓ Branch 0 taken 8572 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8572 times.
8572 else if(Playing && !Paused)
3726 8572 wavy--; // Wavy was set by a script. Decrement it.
3727
3728
3/4
✓ Branch 0 taken 18008436 times.
✓ Branch 1 taken 515682 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18008436 times.
18524118 if(Playing && !Paused)
3729 18008436 ++light_wave_clk;
3730
3731
6/6
✓ Branch 0 taken 18008436 times.
✓ Branch 1 taken 515682 times.
✓ Branch 2 taken 260252 times.
✓ Branch 3 taken 17748184 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 260234 times.
18524118 if(Playing && msg_active && !screenscrolling)
3732 {
3733
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_bg_display_buf->clip))
3734 260167 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,176);
3735
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_portrait_display_buf->clip))
3736 260167 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,176);
3737
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_txt_display_buf->clip))
3738 260167 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,176);
3739 260234 }
3740
3741
3/4
✓ Branch 0 taken 18524118 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18330393 times.
✓ Branch 3 taken 193725 times.
18524118 bool nosubscr = GameLoaded && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET);
3742
3743
2/2
✓ Branch 0 taken 18335666 times.
✓ Branch 1 taken 188452 times.
18524118 if(nosubscr)
3744 {
3745 188452 clear_to_color(panorama, 0);
3746 188452 blit(wavybuf,panorama,0,playing_field_offset,0,playing_field_offset/2,256,framebuf->h-playing_field_offset);
3747 188452 }
3748
3749 //TODO: Optimize blit 'overcalls' -Gleeok
3750
2/2
✓ Branch 0 taken 188452 times.
✓ Branch 1 taken 18335666 times.
18524118 BITMAP *source = nosubscr ? panorama : wavybuf;
3751 18524118 blit(source, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3752
3753 18524118 update_hw_screen();
3754 18524118 }
3755
3756 //----------------------------------------------------------------
3757
3758 static PALETTE syspal;
3759 int32_t onGUISnapshot()
3760 {
3761 char buf[200];
3762 int32_t num=0;
3763 do
3764 {
3765 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3766 }
3767 while(num<99999 && exists(buf));
3768
3769 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3770 InfoDialog("Error", "Failed to save snapshot").show();
3771
3772 return D_O_K;
3773 }
3774
3775 int32_t onNonGUISnapshot()
3776 {
3777 PALETTE temppal;
3778 get_palette(temppal);
3779 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3780
3781 char buf[200];
3782 int32_t num=0;
3783
3784 do
3785 {
3786 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3787 }
3788 while(num<99999 && exists(buf));
3789
3790 if (no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET) && !key[KEY_ALT])
3791 {
3792 BITMAP *b = create_bitmap_ex(8, 256, viewport.visible_height(show_bottom_8px));
3793 clear_to_color(b,0);
3794 blit(framebuf,b,0,playing_field_offset/2,0,0,b->w,b->h);
3795 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3796 destroy_bitmap(b);
3797 }
3798 else
3799 {
3800 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3801 }
3802
3803 return D_O_K;
3804 }
3805
3806 int32_t onSnapshot()
3807 {
3808 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3809 {
3810 onGUISnapshot();
3811 }
3812 else
3813 {
3814 onNonGUISnapshot();
3815 }
3816
3817 return D_O_K;
3818 }
3819
3820 int32_t onSaveMapPic()
3821 {
3822 char buf[200];
3823 int32_t num=0;
3824 BITMAP* _screen_draw_buffer = NULL;
3825 _screen_draw_buffer = create_bitmap_ex(8,256,176);
3826
3827 do
3828 {
3829 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3830 }
3831 while(num<99999 && exists(buf));
3832
3833 BITMAP* mappic = create_bitmap_ex(8,(256*16),(176*8));
3834 clear_to_color(mappic, BLACK);
3835
3836 if(!mappic)
3837 {
3838 enter_sys_pal();
3839 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3840 exit_sys_pal();
3841 return D_O_K;;
3842 }
3843
3844 clear_to_color(_screen_draw_buffer, BLACK);
3845
3846 auto prev_viewport = viewport;
3847 viewport.x = 0;
3848 viewport.y = 0;
3849
3850 // draw the map
3851
3852 bool classic_draw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3853 for(int32_t y=0; y<8; y++)
3854 {
3855 for(int32_t x=0; x<16; x++)
3856 {
3857 if (!displayOnMap(x, y))
3858 continue;
3859
3860 int screen = map_scr_xy_to_index(x, y);
3861 auto scrs = loadscr2(screen);
3862 mapscr* scr = &scrs[0];
3863 if (!scr->is_valid())
3864 continue;
3865
3866 screen_handles_t screen_handles;
3867 for (int i = 0; i <= 6; i++)
3868 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
3869
3870 int xx = 0;
3871 int yy = -playing_field_offset;
3872
3873 if (!classic_draw)
3874 for (int layer = -7; layer <= -4; ++layer)
3875 do_ffc_layer(_screen_draw_buffer, layer, screen_handles[0], xx, yy);
3876
3877 if(classic_draw)
3878 {
3879 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3880 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3881 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3882 }
3883
3884 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3885 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3886 do_ffc_layer(_screen_draw_buffer, -3, screen_handles[0], xx, yy);
3887
3888 if(!classic_draw)
3889 {
3890 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3891 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3892 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3893 do_ffc_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3894 }
3895
3896 if(lenscheck(scr,0))
3897 putscr(scr, _screen_draw_buffer, 0, 0);
3898 do_ffc_layer(_screen_draw_buffer, 0, screen_handles[0], xx, yy);
3899 do_layer(_screen_draw_buffer, 0, screen_handles[1], xx, yy);
3900 do_ffc_layer(_screen_draw_buffer, 1, screen_handles[0], xx, yy);
3901
3902 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3903 {
3904 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3905 do_ffc_layer(_screen_draw_buffer, 2, screen_handles[0], xx, yy);
3906 }
3907
3908 putscrdoors(scr, _screen_draw_buffer, xx, yy);
3909 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3910 {
3911 do_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3912 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3913 {
3914 do_layer(_screen_draw_buffer, -2, screen_handles[1], xx, yy);
3915 do_layer(_screen_draw_buffer, -2, screen_handles[2], xx, yy);
3916 }
3917 }
3918
3919 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3920 {
3921 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3922 do_ffc_layer(_screen_draw_buffer, 3, screen_handles[0], xx, yy);
3923 }
3924
3925 do_layer(_screen_draw_buffer, 0, screen_handles[4], xx, yy);
3926 do_ffc_layer(_screen_draw_buffer, 4, screen_handles[0], xx, yy);
3927 do_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3928 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3929 {
3930 do_layer(_screen_draw_buffer, -1, screen_handles[1], xx, yy);
3931 do_layer(_screen_draw_buffer, -1, screen_handles[2], xx, yy);
3932 }
3933 do_layer(_screen_draw_buffer, 0, screen_handles[5], xx, yy);
3934 do_ffc_layer(_screen_draw_buffer, 5, screen_handles[0], xx, yy);
3935 if(replay_version_check(40))
3936 do_ffc_layer(_screen_draw_buffer, -1000, screen_handles[0], xx, yy);
3937 do_layer(_screen_draw_buffer, 0, screen_handles[6], xx, yy);
3938 do_ffc_layer(_screen_draw_buffer, 6, screen_handles[0], xx, yy);
3939 do_ffc_layer(_screen_draw_buffer, 7, screen_handles[0], xx, yy);
3940
3941 blit(_screen_draw_buffer, mappic, 0, 0, x*256, y*176, 256, 176);
3942 }
3943 }
3944
3945 viewport = prev_viewport;
3946 save_bitmap(buf,mappic,RAMpal);
3947 destroy_bitmap(mappic);
3948 destroy_bitmap(_screen_draw_buffer);
3949 return D_O_K;
3950 }
3951
3952 46 void f_Quit(int32_t type)
3953 {
3954
2/4
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
46 if(type==qQUIT && !Playing)
3955 return;
3956
3957 46 bool from_menu = is_sys_pal;
3958
3959
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(!from_menu)
3960 {
3961 46 music_pause();
3962 46 pause_all_sfx();
3963 46 sys_mouse();
3964 46 }
3965 46 enter_sys_pal();
3966 46 clear_keybuf();
3967
3968
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 13 times.
46 if (replay_version_check(0, 10))
3969 13 replay_poll();
3970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (replay_is_replaying())
3971 46 replay_peek_quit();
3972
3973
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if (!replay_is_replaying())
3974 switch(type)
3975 {
3976 case qQUIT:
3977 onQuit();
3978 break;
3979
3980 case qRESET:
3981 onReset();
3982 break;
3983
3984 case qEXIT:
3985 onExit();
3986 break;
3987 }
3988
3989
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(Quit)
3990 {
3991 46 kill_sfx();
3992 46 music_stop();
3993 46 exit_sys_pal();
3994 46 update_hw_screen();
3995 46 }
3996 else
3997 {
3998 exit_sys_pal();
3999 if(!from_menu)
4000 {
4001 music_resume();
4002 resume_all_sfx();
4003 }
4004 }
4005
4006
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(!from_menu)
4007 46 game_mouse();
4008 46 eat_buttons();
4009
4010 46 zc_readrawkey(KEY_ESC);
4011
4012 46 zc_readrawkey(KEY_ENTER);
4013 46 }
4014
4015 //----------------------------------------------------------------
4016
4017 int32_t onNoWalls()
4018 {
4019 cheats_enqueue(Cheat::Walls);
4020 return D_O_K;
4021 }
4022
4023 int32_t onIgnoreSideview()
4024 {
4025 cheats_enqueue(Cheat::IgnoreSideView);
4026 return D_O_K;
4027 }
4028
4029 18522731 int32_t input_idle(bool checkmouse)
4030 {
4031 static int32_t mx, my, mz, mb;
4032
4033
4/6
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4961269 times.
✓ Branch 3 taken 13561462 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4961269 times.
23484000 if(keypressed() || zc_key_pressed() ||
4034
4/8
✓ Branch 0 taken 4961269 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4961269 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4961269 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4961269 times.
✗ Branch 7 not taken.
4961269 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4035 {
4036 13561462 idle_count = 0;
4037
4038
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13561462 times.
13561462 if(active_count < MAX_ACTIVE)
4039 {
4040 13561462 ++active_count;
4041 13561462 }
4042 13561462 }
4043
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4961269 times.
4961269 else if(idle_count < MAX_IDLE)
4044 {
4045 4961269 ++idle_count;
4046 4961269 active_count = 0;
4047 4961269 }
4048
4049 18522731 mx = mouse_x;
4050 18522731 my = mouse_y;
4051 18522731 mz = mouse_z;
4052 18522731 mb = mouse_b;
4053
4054 18522731 return idle_count;
4055 }
4056
4057 int32_t onGoFast()
4058 {
4059 cheats_enqueue(Cheat::Fast);
4060 return D_O_K;
4061 }
4062
4063 int32_t onKillCheat()
4064 {
4065 cheats_enqueue(Cheat::Kill);
4066 return D_O_K;
4067 }
4068
4069 int32_t onSecretsCheat()
4070 {
4071 cheats_enqueue(Cheat::TrigSecrets);
4072 return D_O_K;
4073 }
4074 int32_t onSecretsCheatPerm()
4075 {
4076 cheats_enqueue(Cheat::TrigSecretsPerm);
4077 return D_O_K;
4078 }
4079
4080 int32_t onShowLayer0()
4081 {
4082 show_layers[0] = !show_layers[0];
4083 return D_O_K;
4084 }
4085 int32_t onShowLayer1()
4086 {
4087 show_layers[1] = !show_layers[1];
4088 return D_O_K;
4089 }
4090 int32_t onShowLayer2()
4091 {
4092 show_layers[2] = !show_layers[2];
4093 return D_O_K;
4094 }
4095 int32_t onShowLayer3()
4096 {
4097 show_layers[3] = !show_layers[3];
4098 return D_O_K;
4099 }
4100 int32_t onShowLayer4()
4101 {
4102 show_layers[4] = !show_layers[4];
4103 return D_O_K;
4104 }
4105 int32_t onShowLayer5()
4106 {
4107 show_layers[5] = !show_layers[5];
4108 return D_O_K;
4109 }
4110 int32_t onShowLayer6()
4111 {
4112 show_layers[6] = !show_layers[6];
4113 return D_O_K;
4114 }
4115 int32_t onShowLayerO()
4116 {
4117 show_layer_over=!show_layer_over;
4118 return D_O_K;
4119 }
4120 int32_t onShowLayerP()
4121 {
4122 show_layer_push=!show_layer_push;
4123 return D_O_K;
4124 }
4125 int32_t onShowLayerS()
4126 {
4127 show_sprites=!show_sprites;
4128 return D_O_K;
4129 }
4130 int32_t onShowLayerF()
4131 {
4132 show_ffcs=!show_ffcs;
4133 return D_O_K;
4134 }
4135 int32_t onShowLayerW()
4136 {
4137 show_walkflags=!show_walkflags;
4138 if(show_walkflags)
4139 show_effectflags = false;
4140 return D_O_K;
4141 }
4142 int32_t onShowLayerE()
4143 {
4144 show_effectflags=!show_effectflags;
4145 if(show_effectflags)
4146 show_walkflags = false;
4147 return D_O_K;
4148 }
4149 int32_t onShowFFScripts()
4150 {
4151 show_ff_scripts=!show_ff_scripts;
4152 return D_O_K;
4153 }
4154 int32_t onShowHitboxes()
4155 {
4156 show_hitboxes=!show_hitboxes;
4157 return D_O_K;
4158 }
4159 int32_t onShowInfoOpacity()
4160 {
4161 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4162 zc_set_config("zc","debug_info_opacity",info_opacity);
4163 return D_O_K;
4164 }
4165
4166 int32_t onLightSwitch()
4167 {
4168 cheats_enqueue(Cheat::Light);
4169 return D_O_K;
4170 }
4171
4172 int32_t onGoTo();
4173 int32_t onGoToComplete();
4174
4175 18522731 bool handle_close_btn_quit()
4176 {
4177
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if(close_button_quit)
4178 {
4179 close_button_quit=false;
4180 f_Quit(qEXIT);
4181 }
4182 18522731 return (exiting_program = Quit==qEXIT);
4183 }
4184
4185 18522731 void syskeys()
4186 {
4187 18522731 update_system_keys();
4188
4189 int32_t oldtitle_version;
4190
4191 18522731 poll_joystick();
4192
4193 18522731 handle_close_btn_quit();
4194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18522731 times.
18522731 if(Quit == qEXIT) return;
4195
4196
2/10
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18522731 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18522731 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4197 {
4198 System();
4199 }
4200
4201 18522731 mouse_down=gui_mouse_b();
4202
4203
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if(zc_read_system_key(KEY_F1))
4204 {
4205 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4206 {
4207 halt=!halt;
4208 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4209 }
4210 else
4211 {
4212 Throttlefps=!Throttlefps;
4213 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4214 }
4215 }
4216
4217
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if(zc_read_system_key(KEY_F2))
4218 {
4219 ShowFPS=!ShowFPS;
4220 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4221 }
4222
4223
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18522731 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18522731 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4224
4225
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18522731 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18522731 if(zc_read_system_key(KEY_F4) && Playing)
4226 {
4227 Paused=true;
4228 Advance=true;
4229 }
4230
4231
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if(zc_read_system_key(KEY_F6)) onTryQuit();
4232
4233 #ifndef ALLEGRO_MACOSX
4234
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4235
4236
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4237 #else
4238 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4239
4240 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4241 #endif
4242
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18522731 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18522731 if(zc_read_system_key(KEY_F5)&&(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)) onSaveMapPic();
4243
4244
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if (zc_read_system_key(KEY_F12))
4245 {
4246 onSnapshot();
4247 }
4248
4249
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18522731 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18522731 if(debug_enabled && zc_read_system_key(KEY_TAB))
4250 set_debug(!get_debug());
4251
4252
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if(CheatModifierKeys())
4253 {
4254 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4255 {
4256 if(!bindable_cheat(c))
4257 continue;
4258 if(get_debug() || cheat >= cheat_lvl(c))
4259 {
4260 if(checkcheat(c))
4261 cheats_hit_bind(c);
4262 }
4263 }
4264 }
4265
4266
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if(volkeys)
4267 {
4268 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4269
4270 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4271
4272 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4273
4274 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4275 }
4276
4277
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18522731 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18522731 if(!get_debug() || !SystemKeys || replay_is_replaying())
4278 18522731 goto bottom;
4279
4280 if(zc_readkey(KEY_P)) Paused=!Paused;
4281
4282 if(zc_readkey(KEY_A))
4283 {
4284 Paused=true;
4285 Advance=true;
4286 }
4287
4288 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4289 #ifndef ALLEGRO_MACOSX
4290 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4291
4292 if(zc_readkey(KEY_F7))
4293 {
4294 Matrix(ss_speed, ss_density, 0);
4295 game_pal();
4296 }
4297 #else
4298 // The reason these are different on Mac in the first place is that
4299 // the OS doesn't let us use F9 and F10...
4300 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4301
4302 if(zc_readkey(KEY_F9))
4303 {
4304 Matrix(ss_speed, ss_density, 0);
4305 game_pal();
4306 }
4307 #endif
4308 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4309 {
4310 //change containers
4311 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4312 {
4313 //magic containers
4314 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4315 {
4316 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4317 }
4318 else
4319 {
4320 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4321 }
4322 }
4323 else
4324 {
4325 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4326 {
4327 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4328 }
4329 else
4330 {
4331 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4332 }
4333 }
4334 }
4335
4336 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4337 {
4338 //change containers
4339 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4340 {
4341 //magic containers
4342 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4343 {
4344 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4345 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4346 //heart containers
4347 }
4348 else
4349 {
4350 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4351 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4352 }
4353 }
4354 else
4355 {
4356 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4357 {
4358 game->set_magic(zc_max(game->get_magic()-1,0));
4359 }
4360 else
4361 {
4362 game->set_life(zc_max(game->get_life()-1,0));
4363 }
4364 }
4365 }
4366
4367 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4368
4369 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4370
4371 verifyBothWeapons();
4372
4373 bottom:
4374
4375
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if(input_idle(true) > after_time())
4376 {
4377 Matrix(ss_speed, ss_density, 0);
4378 game_pal();
4379 }
4380 18522731 }
4381
4382 1356180 void checkQuitKeys()
4383 {
4384 #ifndef ALLEGRO_MACOSX
4385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1356180 times.
1356180 if(key[KEY_F9]) f_Quit(qRESET);
4386
4387
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1356180 times.
1356180 if(key[KEY_F10]) f_Quit(qEXIT);
4388 #else
4389 if(key[KEY_F7]) f_Quit(qRESET);
4390
4391 if(key[KEY_F8]) f_Quit(qEXIT);
4392 #endif
4393 1356180 }
4394
4395 18522931 bool CheatModifierKeys()
4396 {
4397 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4398 // to trigger cheats.
4399
2/2
✓ Branch 0 taken 18522631 times.
✓ Branch 1 taken 300 times.
18522931 if (replay_is_replaying())
4400 18522631 return false;
4401
4402
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4403
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4405 {
4406
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4407 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4408 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4409 {
4410 return true;
4411 }
4412 }
4413 100 return false;
4414 18522731 }
4415
4416 //99:05:54, for some reason?
4417 #define OLDMAXTIME 21405240
4418 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4419 #define MAXTIME 1944000000
4420
4421 // (qr, value)
4422 416 static std::queue<std::pair<int, bool>> change_qr_queue;
4423
4424 7 void enqueue_qr_change(int qr, bool value)
4425 {
4426 7 change_qr_queue.push({qr, value});
4427 7 }
4428
4429 // During regular play, QR changes issued through `syskey` / `System` and enqueued
4430 // and soon executed here.
4431 // During playing back a replay file, the replay system adds to the same queue and
4432 // is executed here too.
4433 // This is currently only used to allow users to configure qr_HIDE_BOTTOM_8_PIXELS, but
4434 // could be later extended to all QRs (perhaps as a cheat).
4435 18523154 void process_enqueued_qr_changes()
4436 {
4437
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 18523053 times.
18523154 if (replay_is_replaying())
4438 18523053 replay_do_qrs();
4439
4440
2/2
✓ Branch 0 taken 18523154 times.
✓ Branch 1 taken 7 times.
18523161 while (!change_qr_queue.empty())
4441 {
4442 28 auto [qr, value] = change_qr_queue.front();
4443 7 change_qr_queue.pop();
4444
4445 // Don't modify `quest_rules`, as that is used to store the canonical QR value which can be reset to
4446 // via system menus. Changing the unpacked array is enough to modify the engine's behavior.
4447 14 _qrs_unpacked[qr] = value;
4448 7 apply_qr_rule(qr);
4449
4450
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (replay_is_recording())
4451 2 replay_step_qr(qr, value);
4452 }
4453 18523154 }
4454
4455 18524118 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4456 {
4457
1/2
✓ Branch 0 taken 18524118 times.
✗ Branch 1 not taken.
18524118 if(zcmusic!=NULL)
4458 {
4459 zcmusic_poll();
4460 }
4461 18524118 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4462
4463 18524118 updatescr(allowwavy);
4464
4465 18524118 Advance=false;
4466
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18524118 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18524118 times.
18524118 while(Paused && !Advance && !Quit)
4467 {
4468 // have to call this, otherwise we'll get an infinite loop
4469 syskeys();
4470 if(allowF6Script)
4471 {
4472 FFCore.runF6Engine();
4473 }
4474
4475 #ifdef _WIN32
4476
4477 if(use_dwm_flush)
4478 {
4479 do_DwmFlush();
4480 }
4481
4482 #endif
4483
4484 // to keep music playing
4485 if(zcmusic!=NULL)
4486 {
4487 zcmusic_poll();
4488 }
4489
4490 update_hw_screen();
4491 }
4492
4493
2/2
✓ Branch 0 taken 18522760 times.
✓ Branch 1 taken 1358 times.
18524118 if(Quit)
4494 1358 return;
4495
4496
3/4
✓ Branch 0 taken 18007390 times.
✓ Branch 1 taken 515370 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18007390 times.
18522760 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4497 18007390 game->change_time(1);
4498
4499 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4500
4501 18522760 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4502
2/2
✓ Branch 0 taken 8723148 times.
✓ Branch 1 taken 9799612 times.
18522760 if (replay_version_check(0, 16))
4503 9799612 should_reset_down_state = replay_version_check(11, 16);
4504
2/2
✓ Branch 0 taken 15093802 times.
✓ Branch 1 taken 3428958 times.
18522760 if (should_reset_down_state)
4505 {
4506
2/2
✓ Branch 0 taken 61721244 times.
✓ Branch 1 taken 3428958 times.
65150202 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4507 61721244 down_control_states[i] = raw_control_state[i];
4508 3428958 }
4509
4510
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 18522731 times.
18522760 if (replay_is_active())
4511 {
4512
2/2
✓ Branch 0 taken 1545428 times.
✓ Branch 1 taken 16977303 times.
18522731 if (replay_version_check(3))
4513 16977303 replay_poll();
4514
4515
4/4
✓ Branch 0 taken 7478911 times.
✓ Branch 1 taken 11043820 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7378376 times.
18522731 if (replay_version_check(11) || replay_version_check(6, 8))
4516 11144355 replay_peek_input();
4517 18522731 }
4518
4519 18522760 process_enqueued_qr_changes();
4520
4521 18522760 load_control_called_this_frame = false;
4522
4523 18522760 poll_keyboard();
4524 18522760 update_keys();
4525
4526 18522760 ++frame;
4527
4528
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 18522631 times.
18522760 if (replay_is_replaying())
4529 18522631 replay_do_cheats();
4530 18522760 syskeys();
4531
4532 // The mouse variables can change from the mouse thread at anytime during a frame,
4533 // so save the result at the start so that replaying is consistent.
4534 18522760 script_mouse_x = gui_mouse_x();
4535 18522760 script_mouse_y = gui_mouse_y();
4536 18522760 script_mouse_z = mouse_z;
4537 18522760 script_mouse_b = mouse_b;
4538
4539 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4540 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4541 // approach here means it doesn't matter which call adds the cheat.
4542 18522760 cheats_execute_queued();
4543
4544
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 18522631 times.
18522760 if (replay_is_replaying())
4545 18522631 replay_peek_quit();
4546
2/2
✓ Branch 0 taken 18522714 times.
✓ Branch 1 taken 46 times.
18522760 if (GameFlags & GAMEFLAG_TRYQUIT)
4547 46 replay_step_quit(0);
4548
2/2
✓ Branch 0 taken 3314 times.
✓ Branch 1 taken 18519446 times.
18522760 if(allowF6Script)
4549 18519446 FFCore.runF6Engine();
4550
2/2
✓ Branch 0 taken 756 times.
✓ Branch 1 taken 18522004 times.
18522760 if (Quit)
4551 756 replay_step_quit(Quit);
4552
4553 #ifdef _WIN32
4554
4555 if(use_dwm_flush)
4556 {
4557 do_DwmFlush();
4558 }
4559
4560 #endif
4561
4562
2/2
✓ Branch 0 taken 208637 times.
✓ Branch 1 taken 18314123 times.
18522760 if(sfxcleanup)
4563 18314123 sfx_cleanup();
4564
4565 18522760 frame_timings_poll();
4566
4567 #ifdef __EMSCRIPTEN__
4568 // Yield the main thread back to the browser occasionally.
4569 if (is_headless())
4570 {
4571 static int rate = 10000;
4572 static int force_yield = rate;
4573 if (force_yield++ >= rate)
4574 {
4575 force_yield = 0;
4576 emscripten_sleep(0);
4577 }
4578 }
4579 #endif
4580
4581
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18522660 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18522760 if (zqtesting_mode && test_mode_auto_restart)
4582 {
4583 static auto last_write_time = fs::last_write_time(qstpath);
4584 static auto last_check = std::chrono::system_clock::now();
4585
4586 if (std::chrono::system_clock::now() - last_check > 200ms)
4587 {
4588 last_check = std::chrono::system_clock::now();
4589 auto write_time = fs::last_write_time(qstpath);
4590 if (last_write_time != write_time)
4591 {
4592 last_write_time = write_time;
4593 disableClickToFreeze = false;
4594 Quit = qRESET;
4595 replay_quit();
4596 }
4597 }
4598 }
4599 18524118 }
4600
4601 590 void zapout()
4602 {
4603 590 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4604 590 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4605
4606 590 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4607 590 script_drawing_commands.Clear();
4608
4609 // zap out
4610
2/2
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 14160 times.
14750 for(int32_t i=1; i<=24; i++)
4611 {
4612 14160 draw_fuzzy(i);
4613 14160 advanceframe(true);
4614
4615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14160 times.
14160 if(Quit)
4616 {
4617 break;
4618 }
4619 14160 }
4620 590 }
4621
4622 588 void zapin()
4623 {
4624 588 FFCore.warpScriptCheck();
4625 588 draw_screen();
4626 588 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4627 588 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4628
4629 // zap out
4630 588 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4631
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 14112 times.
14700 for(int32_t i=24; i>=1; i--)
4632 {
4633 14112 draw_fuzzy(i);
4634 14112 advanceframe(true);
4635
4636
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14112 times.
14112 if(Quit)
4637 {
4638 break;
4639 }
4640 14112 }
4641 588 }
4642
4643
4644 235 void wavyout(bool showhero)
4645 {
4646 235 draw_screen(showhero);
4647
4648 235 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4649 235 clear_to_color(wavebuf,0);
4650 235 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4651
4652 static PALETTE wavepal;
4653
4654 int32_t ofs;
4655 235 int32_t amplitude=8;
4656
4657 235 int32_t wavelength=4;
4658 235 int height = viewport.visible_height(show_bottom_8px);
4659 235 double palpos=0, palstep=4, palstop=126;
4660
4661 235 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4662
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 9845 times.
10079 for(int32_t i=0; i<height; i+=wavelength)
4663 {
4664
2/2
✓ Branch 0 taken 2520320 times.
✓ Branch 1 taken 9845 times.
2530165 for(int32_t l=0; l<256; l++)
4665 {
4666 2520320 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4667 2520320 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4668 2520320 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4669 2520320 }
4670
4671 9845 palpos+=palstep;
4672
4673
1/2
✓ Branch 0 taken 9845 times.
✗ Branch 1 not taken.
9845 if(palpos>=0)
4674 {
4675 9845 hw_palette = &wavepal;
4676 9845 update_hw_pal = true;
4677 9845 }
4678 else
4679 {
4680 hw_palette = &RAMpal;
4681 update_hw_pal = true;
4682 }
4683
4684
2/2
✓ Branch 0 taken 1653960 times.
✓ Branch 1 taken 9845 times.
1663805 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4685 {
4686
2/2
✓ Branch 0 taken 423413760 times.
✓ Branch 1 taken 1653960 times.
425067720 for(int32_t k=0; k<256; k++)
4687 {
4688 423413760 ofs=0;
4689
4690
4/4
✓ Branch 0 taken 206448640 times.
✓ Branch 1 taken 216965120 times.
✓ Branch 2 taken 103224320 times.
✓ Branch 3 taken 103224320 times.
423413760 if((j<i)&&(j&1))
4691 {
4692 103224320 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4693 103224320 }
4694
4695 423413760 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4696 423413760 }
4697 1653960 }
4698
4699 9845 advanceframe(true);
4700
4701
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9844 times.
9845 if(Quit)
4702 1 break;
4703 9844 }
4704
4705 235 destroy_bitmap(wavebuf);
4706
4707 235 hw_palette = &RAMpal;
4708 235 update_hw_pal = true;
4709 235 }
4710
4711 232 void wavyin()
4712 {
4713 232 draw_screen();
4714
4715 232 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4716 232 clear_to_color(wavebuf,0);
4717 232 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4718
4719 static PALETTE wavepal;
4720
4721 232 refreshpal=false;
4722 int32_t ofs;
4723 232 int32_t amplitude=8;
4724 232 int32_t wavelength=4;
4725 232 int height = viewport.visible_height(show_bottom_8px);
4726 232 double palpos=height, palstep=4, palstop=126;
4727
4728 232 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4729
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 9703 times.
9934 for(int32_t i=0; i<height; i+=wavelength)
4730 {
4731
2/2
✓ Branch 0 taken 2483968 times.
✓ Branch 1 taken 9703 times.
2493671 for(int32_t l=0; l<256; l++)
4732 {
4733 2483968 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4734 2483968 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4735 2483968 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4736 2483968 }
4737
4738 9703 palpos-=palstep;
4739
4740
1/2
✓ Branch 0 taken 9703 times.
✗ Branch 1 not taken.
9703 if(palpos>=0)
4741 {
4742 9703 hw_palette = &wavepal;
4743 9703 update_hw_pal = true;
4744 9703 }
4745 else
4746 {
4747 hw_palette = &RAMpal;
4748 update_hw_pal = true;
4749 }
4750
4751
2/2
✓ Branch 0 taken 1630104 times.
✓ Branch 1 taken 9703 times.
1639807 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4752 {
4753
2/2
✓ Branch 0 taken 417306624 times.
✓ Branch 1 taken 1630104 times.
418936728 for(int32_t k=0; k<256; k++)
4754 {
4755 417306624 ofs=0;
4756
4757
4/4
✓ Branch 0 taken 211158272 times.
✓ Branch 1 taken 206148352 times.
✓ Branch 2 taken 106821120 times.
✓ Branch 3 taken 104337152 times.
417306624 if((j<(height-1-i))&&(j&1))
4758 {
4759 104337152 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4760 104337152 }
4761
4762 417306624 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4763 417306624 }
4764 1630104 }
4765
4766 9703 advanceframe(true);
4767
4768
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9702 times.
9703 if(Quit)
4769 1 break;
4770 9702 }
4771
4772 232 destroy_bitmap(wavebuf);
4773
4774 232 hw_palette = &RAMpal;
4775 232 update_hw_pal = true;
4776 232 }
4777
4778 4346 void blackscr(int32_t fcnt,bool showsubscr)
4779 {
4780 4346 reset_pal_cycling();
4781 4346 script_drawing_commands.Clear();
4782
4783 4346 FFCore.warpScriptCheck();
4784 4346 bool showtime = game->should_show_time();
4785
2/2
✓ Branch 0 taken 4339 times.
✓ Branch 1 taken 129937 times.
134276 while(fcnt>0)
4786 {
4787 129937 clear_bitmap(framebuf);
4788
4789
2/2
✓ Branch 0 taken 59310 times.
✓ Branch 1 taken 70627 times.
129937 if(showsubscr)
4790 {
4791 70627 put_passive_subscr(framebuf,0,0,showtime,sspUP);
4792
3/4
✓ Branch 0 taken 70627 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1410 times.
✓ Branch 3 taken 69217 times.
70627 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4793 {
4794 1410 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
4795 1410 }
4796 70627 }
4797
4798 129937 advanceframe(true);
4799
4800
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129930 times.
129937 if(Quit)
4801 7 break;
4802
4803 129930 --fcnt;
4804 }
4805 4346 }
4806
4807 2739 void openscreen(int32_t shape)
4808 {
4809 2739 update_viewport();
4810 2739 is_opening_screen = true;
4811 2739 reset_pal_cycling();
4812 2739 black_opening_count=0;
4813
4814
3/4
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 2208 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 531 times.
2739 if(COOLSCROLL || shape>-1)
4815 {
4816 2208 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4817 2208 return;
4818 }
4819 else
4820 {
4821 531 Hero.setDontDraw(true);
4822 531 show_subscreen_dmap_dots=false;
4823 531 show_subscreen_numbers=false;
4824 531 show_subscreen_life=false;
4825 }
4826
4827 531 int32_t x=128;
4828
4829 531 FFCore.warpScriptCheck();
4830
2/2
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 42480 times.
43011 for(int32_t i=0; i<80; i++)
4831 {
4832 42480 draw_screen();
4833 42480 x=128-(((i*128/80)/8)*8);
4834
4835
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42480 times.
42480 if(x>0)
4836 {
4837 42480 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4838 42480 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4839 42480 }
4840
4841 42480 advanceframe(true);
4842
4843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42480 times.
42480 if(Quit)
4844 {
4845 break;
4846 }
4847 42480 }
4848
4849 531 Hero.setDontDraw(false);
4850 531 show_subscreen_items=true;
4851 531 show_subscreen_dmap_dots=true;
4852 531 show_subscreen_numbers=true;
4853 531 show_subscreen_life=true;
4854 2739 }
4855
4856 14 void closescreen(int32_t shape)
4857 {
4858 14 is_opening_screen = false;
4859 14 reset_pal_cycling();
4860 14 black_opening_count=0;
4861
4862
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(COOLSCROLL || shape>-1)
4863 {
4864 14 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4865 14 return;
4866 }
4867 else
4868 {
4869 Hero.setDontDraw(true);
4870 show_subscreen_dmap_dots=false;
4871 show_subscreen_numbers=false;
4872 // show_subscreen_items=false;
4873 show_subscreen_life=false;
4874 }
4875
4876 int32_t x=128;
4877
4878 FFCore.warpScriptCheck();
4879 for(int32_t i=79; i>=0; --i)
4880 {
4881 draw_screen();
4882 x=128-(((i*128/80)/8)*8);
4883
4884 if(x>0)
4885 {
4886 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4887 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4888 }
4889
4890 advanceframe(true);
4891
4892 if(Quit)
4893 {
4894 break;
4895 }
4896 }
4897
4898 Hero.setDontDraw(false);
4899 show_subscreen_items=true;
4900 show_subscreen_dmap_dots=true;
4901 14 }
4902
4903 324 int32_t TriforceCount()
4904 {
4905 324 int32_t c=0;
4906
4907
2/2
✓ Branch 0 taken 2592 times.
✓ Branch 1 taken 324 times.
2916 for(int32_t i=1; i<=8; i++)
4908
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 2108 times.
4700 if(game->lvlitems[i]&(1 << li_mcguffin))
4909 2108 ++c;
4910
4911 324 return c;
4912 }
4913
4914 int32_t onCustomGame()
4915 {
4916 auto save = get_unset_save_slot();
4917 if (!save)
4918 return D_CLOSE;
4919
4920 if (prompt_for_quest_path(save->header->qstpath))
4921 {
4922 save->header->qstpath = qstpath;
4923 return D_O_K;
4924 }
4925
4926 return D_CLOSE;
4927 }
4928
4929 int32_t onContinue()
4930 {
4931 return D_CLOSE;
4932 }
4933
4934 int32_t onThrottleFPS()
4935 {
4936 Throttlefps = !Throttlefps;
4937 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4938 return D_O_K;
4939 }
4940
4941 int32_t onWinPosSave()
4942 {
4943 SaveWinPos = !SaveWinPos;
4944 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4945 return D_O_K;
4946 }
4947 int32_t onIntegerScaling()
4948 {
4949 scaleForceInteger = !scaleForceInteger;
4950 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4951 return D_O_K;
4952 }
4953 int32_t onStretchGame()
4954 {
4955 stretchGame = !stretchGame;
4956 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4957 return D_O_K;
4958 }
4959
4960 int32_t onClickToFreeze()
4961 {
4962 ClickToFreeze = !ClickToFreeze;
4963 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4964 return D_O_K;
4965 }
4966
4967 int32_t OnSaveZCConfig()
4968 {
4969 if(jwin_alert3(
4970 "Save Configuration",
4971 "Are you sure that you wish to save your present configuration settings?",
4972 "This will overwrite your prior settings!",
4973 NULL,
4974 "&Yes",
4975 "&No",
4976 NULL,
4977 'y',
4978 'n',
4979 0,
4980 get_zc_font(font_lfont)) == 1)
4981 {
4982 save_game_configs();
4983 return D_O_K;
4984 }
4985 else return D_O_K;
4986 }
4987
4988 int32_t OnnClearQuestDir()
4989 {
4990 auto current_path = fs::current_path() / "quests";
4991 if(jwin_alert3(
4992 "Clear Current Directory Cache",
4993 "Are you sure that you wish to reset where ZC Player looks for quests?",
4994 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4995 NULL,
4996 "&Yes",
4997 "&No",
4998 NULL,
4999 'y',
5000 'n',
5001 0,
5002 get_zc_font(font_lfont)) == 1)
5003 {
5004 zc_set_config("zeldadx","quest_dir","quests");
5005 flush_config_file();
5006 strcpy(qstdir,"quests");
5007 #ifdef __EMSCRIPTEN__
5008 em_sync_fs();
5009 #endif
5010 return D_O_K;
5011 }
5012 else return D_O_K;
5013 }
5014
5015 int32_t onConsole()
5016 {
5017 if ( !console_enabled )
5018 {
5019 AlertDialog("ZC Console",
5020 "Open the ZC Console?"
5021 "\nThis will display any messages logged by scripts,"
5022 " including errors.",
5023 [&](bool ret,bool)
5024 {
5025 if(ret)
5026 {
5027 FFCore.ZScriptConsole(true);
5028 }
5029 }).show();
5030 return D_O_K;
5031 }
5032 else
5033 {
5034 FFCore.ZScriptConsole(false);
5035 return D_O_K;
5036 }
5037 }
5038
5039 int32_t onClrConsoleOnReload()
5040 {
5041 clearConsoleOnReload = !clearConsoleOnReload;
5042 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5043 return D_O_K;
5044 }
5045 int32_t onClrConsoleOnLoad()
5046 {
5047 clearConsoleOnLoad = !clearConsoleOnLoad;
5048 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5049 return D_O_K;
5050 }
5051
5052
5053 int32_t onFrameSkip()
5054 {
5055 FrameSkip = !FrameSkip;
5056 return D_O_K;
5057 }
5058
5059 int32_t onSaveDragResize()
5060 {
5061 SaveDragResize = !SaveDragResize;
5062 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5063 return D_O_K;
5064 }
5065
5066 int32_t onDragAspect()
5067 {
5068 DragAspect = !DragAspect;
5069 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5070 return D_O_K;
5071 }
5072
5073 int32_t onTransLayers()
5074 {
5075 TransLayers = !TransLayers;
5076 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5077 return D_O_K;
5078 }
5079
5080 int32_t onNESquit()
5081 {
5082 NESquit = !NESquit;
5083 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5084 return D_O_K;
5085 }
5086
5087 int32_t onVolKeys()
5088 {
5089 volkeys = !volkeys;
5090 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5091 return D_O_K;
5092 }
5093
5094 int32_t onShowFPS()
5095 {
5096 ShowFPS = !ShowFPS;
5097 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5098 return D_O_K;
5099 }
5100
5101 int32_t onShowTime()
5102 {
5103 ShowGameTime = !ShowGameTime;
5104 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5105 return D_O_K;
5106 }
5107
5108 2185682258 bool is_Fkey(int32_t k)
5109 {
5110
2/2
✓ Branch 0 taken 222272772 times.
✓ Branch 1 taken 1963409486 times.
2185682258 switch(k)
5111 {
5112 case KEY_F1:
5113 case KEY_F2:
5114 case KEY_F3:
5115 case KEY_F4:
5116 case KEY_F5:
5117 case KEY_F6:
5118 case KEY_F7:
5119 case KEY_F8:
5120 case KEY_F9:
5121 case KEY_F10:
5122 case KEY_F11:
5123 case KEY_F12:
5124 222272772 return true;
5125 }
5126
5127 1963409486 return false;
5128 2185682258 }
5129
5130 void kb_getkey(DIALOG *d);
5131
5132 //Used by all keyboard key settings dialogues.
5133 void kb_clearjoystick(DIALOG *d)
5134 {
5135 d->flags|=D_SELECTED;
5136
5137 jwin_button_proc(MSG_DRAW,d,0);
5138 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5139 // text_mode(vc(11));
5140 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5141 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5142
5143 update_hw_screen();
5144
5145 clear_keybuf();
5146 int32_t k = next_press_key();
5147 clear_keybuf();
5148
5149 //shnarf
5150 //47=f1
5151 //59=esc
5152 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5153 // *((int32_t*)d->dp3) = k;
5154 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5155
5156
5157 d->flags&=~D_SELECTED;
5158 }
5159
5160 //Clears key to 0.
5161 //Used by all keyboard key settings dialogues.
5162 void kb_clearkey(DIALOG *d);
5163
5164 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5165 {
5166 switch(msg)
5167 {
5168 case MSG_KEY:
5169 case MSG_CLICK:
5170
5171 kb_clearjoystick(d);
5172
5173 while(gui_mouse_b())
5174 {
5175 clear_keybuf();
5176 rest(1);
5177 }
5178
5179 return D_REDRAW;
5180 }
5181
5182 return jwin_button_proc(msg,d,c);
5183 }
5184
5185 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5186 //Only used in keyboard settings dialogues to clear keys.
5187 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5188
5189 int32_t j_getbtn(DIALOG *d)
5190 {
5191 d->flags|=D_SELECTED;
5192 jwin_button_proc(MSG_DRAW,d,0);
5193 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5194 // text_mode(vc(11));
5195 int32_t y = screen->h/2 - 12;
5196 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5197 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5198 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5199
5200 update_hw_screen();
5201
5202 int32_t b = next_joy_input(true);
5203 if (b == -2)
5204 return D_CLOSE;
5205
5206 if(b>=0)
5207 *((int32_t*)d->dp3) = b;
5208
5209 d->flags&=~D_SELECTED;
5210
5211 return D_O_K;
5212 }
5213
5214 void j_getstick(DIALOG *d)
5215 {
5216 d->flags|=D_SELECTED;
5217 jwin_button_proc(MSG_DRAW,d,0);
5218 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5219 // text_mode(vc(11));
5220 int32_t y = screen->h/2 - 12;
5221 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5222 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5223 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5224
5225 update_hw_screen();
5226
5227 int32_t b = next_joy_input(false);
5228
5229 if(b>=0)
5230 *((int32_t*)d->dp3) = b;
5231
5232 d->flags&=~D_SELECTED;
5233 }
5234
5235 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5236 {
5237 switch(msg)
5238 {
5239 case MSG_KEY:
5240 case MSG_CLICK:
5241
5242 int ret = j_getbtn(d);
5243 if (ret != D_O_K)
5244 return ret;
5245
5246 while(gui_mouse_b()) {
5247 rest(1);
5248 clear_keybuf();
5249 }
5250
5251 return D_REDRAW;
5252 }
5253
5254 return jwin_button_proc(msg,d,c);
5255 }
5256
5257 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5258 {
5259 switch(msg)
5260 {
5261 case MSG_KEY:
5262 case MSG_CLICK:
5263
5264 j_getstick(d);
5265
5266 while(gui_mouse_b()) {
5267 rest(1);
5268 clear_keybuf();
5269 }
5270
5271 return D_REDRAW;
5272 }
5273
5274 return jwin_button_proc(msg,d,c);
5275 }
5276
5277 //shnarf
5278 extern const char *key_str[];
5279 std::string get_keystr(int key);
5280
5281 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5282
5283 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5284 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5285 str_primary_stick[80], str_secondary_stick[80];
5286
5287 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5288 {
5289 //these are here to bypass compiler warnings about unused arguments
5290 c=c;
5291
5292 if (d->w == 1)
5293 {
5294 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5295 {
5296 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5297 return D_CLOSE;
5298 }
5299 }
5300
5301 if(msg==MSG_DRAW)
5302 {
5303 switch(d->w)
5304 {
5305 case 0:
5306 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5307 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5308 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5309 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5310 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5311 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5312 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5313 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5314 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5315 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5316 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5317 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5318 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5319 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5320 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5321 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5322 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5323 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5324 break;
5325
5326 case 1:
5327 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5328 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5329 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5330 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5331 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5332 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5333 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5334 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5335 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5336 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5337 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5338 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5339 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5340 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5341 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5342 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5343 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5344 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5345 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5346 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5347 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5348 break;
5349
5350 case 2:
5351 sprintf(str_a," %3d",midi_volume);
5352 sprintf(str_l," %3d",emusic_volume);
5353 sprintf(str_r," %3d",sfx_volume);
5354 strcpy(str_s,pan_str[pan_style]);
5355 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5356 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5357 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5358 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5359 break;
5360 }
5361 }
5362
5363 return D_O_K;
5364 }
5365
5366 int32_t set_vol(void *dp3, int32_t d2)
5367 {
5368 switch(((int32_t*)dp3)[0])
5369 {
5370 case 0:
5371 midi_volume = zc_min(d2<<3,255);
5372 break;
5373
5374 case 1:
5375 digi_volume = zc_min(d2<<3,255);
5376 break;
5377
5378 case 2:
5379 emusic_volume = zc_min(d2<<3,255);
5380 break;
5381
5382 case 3:
5383 sfx_volume = zc_min(d2<<3,255);
5384 break;
5385 }
5386
5387 // text_mode(vc(11));
5388 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5389 return D_O_K;
5390 }
5391
5392 int32_t set_pan(void *dp3, int32_t d2)
5393 {
5394 pan_style = vbound(d2,0,3);
5395 // text_mode(vc(11));
5396 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5397 return D_O_K;
5398 }
5399
5400 static int32_t gamepad_joys_list[] =
5401 {
5402 61,
5403 -1
5404 };
5405
5406 static int32_t gamepad_btn_list[] =
5407 {
5408 6,
5409 7,8,9,10,11,12,13,14,15,16,17,
5410 18,19,20,21,22,23,24,25,26,27,28,
5411 29,30,31,32,33,34,35,36,37,38,39,
5412 -1
5413 };
5414
5415 static int32_t gamepad_dirs_list[] =
5416 {
5417 40,41,42,43,
5418 44,45,46,47,
5419 48,49,50,51,
5420 52,53,54,55,
5421 56,57,58,59,
5422 60,
5423 -1
5424 };
5425
5426 static TABPANEL gamepad_tabs[] =
5427 {
5428 // (text)
5429 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5430 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5431 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5432 { NULL, 0, NULL, 0, NULL }
5433 };
5434
5435 const char *joy_list(int32_t index, int32_t *list_size)
5436 {
5437 if (index == -1)
5438 {
5439 *list_size = al_get_num_joysticks();
5440 return NULL;
5441 }
5442
5443 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5444 if (!joy)
5445 {
5446 return "?";
5447 }
5448
5449 return al_get_joystick_name(joy);
5450 }
5451
5452 416 static ListData joy__list(joy_list, &font);
5453
5454 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5455 {
5456 int32_t d2 = d->d2;
5457 int32_t ret = jwin_droplist_proc(msg,d,c);
5458
5459 if(d2!=d->d2)
5460 {
5461 joystick_index = d->d2;
5462 ret |= D_REDRAW_ALL;
5463 }
5464
5465 return ret;
5466 }
5467
5468 static DIALOG gamepad_dlg[] =
5469 {
5470 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5471 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5472 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5473 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5474 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5475 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5476 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5477 // 6
5478 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5479 // 7
5480 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5481 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5482 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5483 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5484 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5485 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5486 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5487 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5488 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5489 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5490 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5491 // 18
5492 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5493 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5494 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5495 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5496 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5497 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5498 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5499 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5500 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5501 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5502 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5503 // 29
5504 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5505 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5506 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5507 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5508 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5509 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5510 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5511 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5512 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5513 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5514 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5515 // 40
5516 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5517 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5518 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5519 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5520 // 44
5521 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5522 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5523 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5524 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5525 // 48
5526 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5527 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5528 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5529 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5530 // 52
5531 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5532 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5533 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5534 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5535 // 56
5536 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5537 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5538 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5539 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5540 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5541
5542 // 61
5543 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5544
5545 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5546 };
5547
5548 static int32_t keyboard_keys_list[] =
5549 {
5550 6,7,8,9,10,
5551 11,12,13,14,15,16,17,18,19,20,
5552 21,22,23,24,25,26,27,28,29,30,
5553 31,32,33,34,35,36,37,38,39,40,
5554 -1
5555 };
5556
5557 static int32_t keyboard_dirs_list[] =
5558 {
5559 41,42,43,44,
5560 45,46,47,48,
5561 49,50,51,52,
5562 53,54,55,56,
5563 -1
5564 };
5565
5566 static int32_t keyboard_mods_list[] =
5567 {
5568 57,58,59,60,
5569 61,62,63,64,
5570 65,66,67,68,
5571 69,70,71,72,
5572 -1
5573 };
5574
5575 static TABPANEL keyboard_control_tabs[] =
5576 {
5577 // (text)
5578 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5579 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5580 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5581 { NULL, 0, NULL, 0, NULL }
5582 };
5583
5584 static DIALOG keyboard_control_dlg[] =
5585 {
5586 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5587 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5588 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5589 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5590 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5591 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5592 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5593 // Keys
5594 // 6
5595 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5596 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5597 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5598 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5599 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5600 // 11
5601 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5602 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5603 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5604 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5605 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5606 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5607 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5608 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5609 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5610 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5611 // 21
5612 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5613 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5614 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5615 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5616 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5617 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5618 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5619 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5620 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5621 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5622 // 31
5623 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5624 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5625 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5626 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5627 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5628 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5629 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5630 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5631 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5632 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5633 // Dirs
5634 // 41
5635 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5636 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5637 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5638 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5639 // 45
5640 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5641 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5642 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5643 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5644 // 49
5645 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5646 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5647 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5648 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5649 // 53
5650 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5651 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5652 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5653 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5654 // Mods
5655 // 57
5656 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5657 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5658 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5659 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5660 // 61
5661 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5662 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5663 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5664 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5665 // 65
5666 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5667 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5668 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5669 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5670 // 69
5671 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5672 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5673 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5674 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5675 // 73
5676 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5677 };
5678
5679 int32_t midi_dp[3] = {0,0,0};
5680 int32_t emus_dp[3] = {2,0,0};
5681 int32_t sfx_dp[3] = {3,0,0};
5682 int32_t pan_dp[3] = {0,0,0};
5683
5684 static DIALOG sound_dlg[] =
5685 {
5686 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5687 416 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5688 416 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5689 416 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5690 416 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5691 416 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5692 416 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5693 416 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5694 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5695 416 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5696 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5697 // 10
5698 416 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5699 416 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5700 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5701 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5702 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5703 416 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5704 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5705 416 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5706 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5707 416 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5708 //20
5709 416 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5710 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5711 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5712 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5713 416 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5714 416 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5715 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5716 416 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5717 416 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5718 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5719 //30
5720 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5721 416 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5722 416 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5723 };
5724
5725 char zc_builddate[80];
5726 char zc_aboutstr[80];
5727
5728 static DIALOG about_dlg[] =
5729 {
5730 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5731 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5732 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5733 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5734 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5735 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5736 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5737 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5738 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5739 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5740 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5741 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5742 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5743 };
5744
5745
5746 static DIALOG quest_dlg[] =
5747 {
5748 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5749 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5750 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5751 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5752 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5753 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5754 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5755 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5756 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5757 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5758 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5759 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5760 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5761 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5762 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5763 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5764 };
5765
5766 static DIALOG triforce_dlg[] =
5767 {
5768 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5769 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5770 // 1
5771 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5772 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5773 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5774 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5775 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5776 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5777 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5778 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5779 // 9
5780 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5781 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5782 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5783 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5784 };
5785
5786 int32_t onToggleRecordingNewSaves()
5787 {
5788 if (zc_get_config("zeldadx", "replay_new_saves", false))
5789 {
5790 zc_set_config("zeldadx", "replay_new_saves", false);
5791 }
5792 else
5793 {
5794 zc_set_config("zeldadx", "replay_new_saves", true);
5795 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5796 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5797 }
5798 return D_O_K;
5799 }
5800
5801 #ifdef HAS_CURL
5802 int32_t onToggleAutoUploadReplays()
5803 {
5804 if (zc_get_config("zeldadx", "replay_upload", false))
5805 {
5806 zc_set_config("zeldadx", "replay_upload", false);
5807 }
5808 else
5809 {
5810 zc_set_config("zeldadx", "replay_upload", true);
5811 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5812 " preventing bugs and simplifying bug reports.",
5813 "Upload will happen no more than once a week when closing ZC",
5814 "OK",NULL,13,27,get_zc_font(font_lfont));
5815
5816 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5817 onToggleRecordingNewSaves();
5818 }
5819 return D_O_K;
5820 }
5821
5822 int32_t onUploadReplays()
5823 {
5824 if(jwin_alert3(
5825 "Upload replays",
5826 "Upload your replays now to assist in development?",
5827 NULL,
5828 NULL,
5829 "&Yes",
5830 "&No",
5831 NULL,
5832 'y',
5833 'n',
5834 0,
5835 get_zc_font(font_lfont)) == 1)
5836 {
5837 int num_uploaded = replay_upload();
5838 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5839 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5840 }
5841 return D_O_K;
5842 }
5843
5844 int32_t onClearUploadCache()
5845 {
5846 if(jwin_alert3(
5847 "Upload replays",
5848 "Clear the upload cache?",
5849 "This simply deletes replays/state.json. There's no harm in doing this, but",
5850 "likely is not necessary.",
5851 "&Yes",
5852 "&No",
5853 NULL,
5854 'y',
5855 'n',
5856 0,
5857 get_zc_font(font_lfont)) == 1)
5858 {
5859 replay_upload_clear_cache();
5860 }
5861 return D_O_K;
5862 }
5863 #endif
5864
5865 int32_t onToggleSnapshotAllFrames()
5866 {
5867 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5868 return D_O_K;
5869 }
5870
5871 int32_t onStopReplayOrRecord()
5872 {
5873 if (replay_is_replaying())
5874 {
5875 replay_quit();
5876 }
5877 else if (replay_get_mode() == ReplayMode::Record)
5878 {
5879 if (!replay_get_meta_bool("test_mode"))
5880 {
5881 jwin_alert("Recording", "You cannot stop recording a save file.",
5882 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5883 return D_CLOSE;
5884 }
5885
5886 if (jwin_alert("Stop Recording",
5887 "Save replay to disk and stop recording?",
5888 "This will stop the recording.",
5889 NULL,
5890 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5891 return D_CLOSE;
5892
5893 replay_save();
5894 replay_stop();
5895 }
5896 return D_O_K;
5897 }
5898
5899 static int32_t handle_on_load_replay(ReplayMode mode)
5900 {
5901 bool ctrl = CHECK_CTRL_CMD;
5902 if (Playing)
5903 {
5904 if (jwin_alert("Replay - Warning!",
5905 "Loading a replay will exit the current game.",
5906 "All unsaved progress will be lost.",
5907 "Do you wish to continue?",
5908 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5909 return D_CLOSE;
5910 }
5911
5912 std::string mode_string = replay_mode_to_string(mode);
5913 mode_string[0] = std::toupper(mode_string[0]);
5914
5915 std::string line_1 = "Select a replay file to play back.";
5916 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5917 std::string line_3 = "You can stop the replay and take over manually any time.";
5918 if (mode == ReplayMode::Update)
5919 {
5920 line_1 = "Select a replay file to update.";
5921 line_2 = "WARNING: be sure to back up the zplay file";
5922 line_3 = "and verify that the updated replay works as expected!";
5923 }
5924
5925 if (jwin_alert(mode_string.c_str(),
5926 line_1.c_str(),
5927 line_2.c_str(),
5928 line_3.c_str(),
5929 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5930 {
5931 std::string replay_path = "replays/";
5932 if(ctrl && devpwd())
5933 replay_path = "../../tests/replays/";
5934 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5935 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5936 replay_path = *result;
5937 else
5938 return D_CLOSE;
5939
5940 replay_quit();
5941 load_replay_file_deferred(mode, replay_path);
5942 Quit = qRESET;
5943 return D_CLOSE;
5944 }
5945 return D_O_K;
5946 }
5947
5948 int32_t onLoadReplay()
5949 {
5950 return handle_on_load_replay(ReplayMode::Replay);
5951 }
5952
5953 int32_t onLoadReplayAssert()
5954 {
5955 return handle_on_load_replay(ReplayMode::Assert);
5956 }
5957
5958 int32_t onLoadReplayUpdate()
5959 {
5960 return handle_on_load_replay(ReplayMode::Update);
5961 }
5962
5963 int32_t onSaveReplay()
5964 {
5965 if (replay_get_mode() == ReplayMode::Record)
5966 {
5967 if (!replay_get_meta_bool("test_mode"))
5968 {
5969 if (jwin_alert("Save Replay",
5970 "This will save a copy of the replay up to this point.",
5971 "The official replay file will be untouched.",
5972 "Do you wish to continue?",
5973 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5974 {
5975 return D_CLOSE;
5976 }
5977
5978 std::string replay_path = replay_get_replay_path().string();
5979 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5980 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5981 replay_path = *result;
5982 else
5983 return D_CLOSE;
5984
5985 if (fileexists(replay_path.c_str()))
5986 {
5987 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5988 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5989 return D_CLOSE;
5990 }
5991
5992 replay_save(replay_path);
5993 }
5994 else
5995 {
5996 replay_save();
5997 }
5998 }
5999 return D_O_K;
6000 }
6001
6002 enum
6003 {
6004 MENUID_REPLAY_RECORDNEW,
6005 MENUID_REPLAY_STOP,
6006 MENUID_REPLAY_SAVE,
6007 MENUID_REPLAY_SNAP_ALL,
6008 MENUID_REPLAY_AUTOUPLOAD,
6009 MENUID_REPLAY_UPLOAD,
6010 MENUID_REPLAY_CLEARUPLOADCACHE,
6011 };
6012
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu replay_menu
6013 5408 {
6014
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
6015
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
6016
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
6017
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Load replay", onLoadReplay },
6018
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Load replay (assert)", onLoadReplayAssert },
6019
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Load replay (update)", onLoadReplayUpdate },
6020
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
6021
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
6022 #ifdef HAS_CURL
6023
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
6024
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
6025
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
6026
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
6027 #endif
6028 };
6029
6030 static DIALOG credits_dlg[] =
6031 {
6032 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6033 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6034 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6035 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6036 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6037 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6038 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6039 };
6040
6041 416 static ListData dmap_list(dmaplist, &font);
6042
6043 static DIALOG goto_dlg[] =
6044 {
6045 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6046 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6047 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6048 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6049 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6050 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6051 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6052 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6053 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6054 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6055 };
6056
6057 int32_t onGoTo()
6058 {
6059 bool music = false;
6060 music = music;
6061 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6062
6063 goto_dlg[0].dp2=get_zc_font(font_lfont);
6064 goto_dlg[4].d2=cheat_goto_dmap;
6065 goto_dlg[6].dp=cheat_goto_screen_str;
6066
6067 clear_keybuf();
6068
6069 large_dialog(goto_dlg);
6070
6071 if(do_zqdialog(goto_dlg,4)==1)
6072 {
6073 int dmap = goto_dlg[4].d2;
6074 int screen = zc_xtoi(cheat_goto_screen_str);
6075 int adjusted_screen = screen + DMaps[dmap].xoff;
6076 if (adjusted_screen < 0 || adjusted_screen >= 128)
6077 {
6078 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6079 }
6080 else
6081 {
6082 cheats_enqueue(Cheat::GoTo, dmap, screen);
6083 }
6084 };
6085
6086 return D_O_K;
6087 }
6088
6089 int32_t onGoToComplete()
6090 {
6091 if(!Playing)
6092 {
6093 return D_O_K;
6094 }
6095
6096 enter_sys_pal();
6097 music_pause();
6098 pause_all_sfx();
6099 onGoTo();
6100 eat_buttons();
6101
6102 zc_readrawkey(KEY_ESC);
6103
6104 exit_sys_pal();
6105 music_resume();
6106 resume_all_sfx();
6107 return D_O_K;
6108 }
6109
6110 int32_t onCredits()
6111 {
6112 return D_O_K;
6113 }
6114
6115 const char *midilist(int32_t index, int32_t *list_size)
6116 {
6117 if(index<0)
6118 {
6119 *list_size=0;
6120
6121 for(int32_t i=0; i<MAXMIDIS; i++)
6122 if(tunes[i].data)
6123 ++(*list_size);
6124
6125 return NULL;
6126 }
6127
6128 int32_t i=0,m=0;
6129
6130 while(m<=index && i<=MAXMIDIS)
6131 {
6132 if(tunes[i].data)
6133 ++m;
6134
6135 ++i;
6136 }
6137
6138 --i;
6139
6140 if(i==MAXMIDIS && m<index)
6141 return "(null)";
6142
6143 return tunes[i].title;
6144 }
6145
6146 /* ------- MIDI info stuff -------- */
6147
6148 char *text;
6149 midi_info *zmi;
6150 bool dialog_running;
6151 bool listening;
6152
6153 void get_info(int32_t index);
6154
6155 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6156 {
6157 int32_t d2 = d->d2;
6158 int32_t ret = jwin_droplist_proc(msg,d,c);
6159
6160 if(d2!=d->d2)
6161 {
6162 get_info(d->d2);
6163 }
6164
6165 return ret;
6166 }
6167
6168 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6169 {
6170 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6171
6172 int32_t ret = jwin_button_proc(msg,d,c);
6173
6174 if(ret == D_CLOSE)
6175 {
6176 // get current midi index
6177 int32_t index = (d+(d->d1))->d2;
6178 int32_t i=0, m=0;
6179
6180 while(m<=index && i<=MAXMIDIS)
6181 {
6182 if(tunes[i].data)
6183 ++m;
6184
6185 ++i;
6186 }
6187
6188 --i;
6189 jukebox(i);
6190 listening = true;
6191 ret = D_O_K;
6192 }
6193
6194 return ret;
6195 }
6196
6197 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6198 {
6199 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6200
6201 int32_t ret = jwin_button_proc(msg,d,c);
6202
6203 if(ret == D_CLOSE)
6204 {
6205 // get current midi index
6206 int32_t index = (d+(d->d1))->d2;
6207 int32_t i=0, m=0;
6208
6209 while(m<=index && i<=MAXMIDIS)
6210 {
6211 if(tunes[i].data)
6212 ++m;
6213
6214 ++i;
6215 }
6216
6217 --i;
6218
6219 char title[40] = "Save MIDI: ";
6220 static EXT_LIST list[] =
6221 {
6222 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6223 { NULL, NULL }
6224 };
6225
6226 strcpy(title+11, tunes[i].title);
6227 title[39] = '\0';
6228
6229 std::string fname;
6230 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6231 fname = *result;
6232 else
6233 goto done;
6234
6235 if(exists(fname.c_str()))
6236 {
6237 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6238 goto done;
6239 }
6240
6241 // save midi i
6242
6243 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6244 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6245
6246 done:
6247 chop_path(fname.data());
6248 ret = D_REDRAW;
6249 }
6250
6251 return ret;
6252 }
6253
6254 416 static ListData midi_list(midilist, &font);
6255
6256 static DIALOG midi_dlg[] =
6257 {
6258 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6259 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6260 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6261 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6262 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6263 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6264 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6265 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6266 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6267 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6268 };
6269
6270 void get_info(int32_t index)
6271 {
6272 int32_t i=0, m=0;
6273
6274 while(m<=index && i<=MAXMIDIS)
6275 {
6276 if(tunes[i].data)
6277 ++m;
6278
6279 ++i;
6280 }
6281
6282 --i;
6283
6284 if(i==MAXMIDIS && m<index)
6285 strcpy(text,"(null)");
6286 else
6287 {
6288 get_midi_info(tunes[i].data,zmi);
6289 get_midi_text(tunes[i].data,zmi,text);
6290 }
6291
6292 midi_dlg[0].dp2=get_zc_font(font_lfont);
6293 midi_dlg[3].dp = text;
6294 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6295 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6296
6297 if(dialog_running)
6298 {
6299 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6300 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6301 }
6302 }
6303
6304 int32_t onMIDICredits()
6305 {
6306 text = (char*)malloc(4096);
6307 zmi = (midi_info*)malloc(sizeof(midi_info));
6308
6309 if(!text || !zmi)
6310 {
6311 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6312 return D_O_K;
6313 }
6314
6315 bool do_pause_midi = midi_pos >= 0 && currmidi;
6316 auto restore_midi = currmidi;
6317 if(do_pause_midi)
6318 {
6319 paused_midi_pos = midi_pos;
6320 stop_midi();
6321 midi_suspended = midissuspHALTED;
6322 }
6323
6324 midi_dlg[0].dp2=get_zc_font(font_lfont);
6325 midi_dlg[2].d1 = 0;
6326 midi_dlg[2].d2 = 0;
6327 midi_dlg[4].flags = D_EXIT;
6328 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6329
6330 listening = false;
6331 dialog_running=false;
6332 get_info(0);
6333
6334 dialog_running=true;
6335
6336 large_dialog(midi_dlg);
6337
6338 do_zqdialog(midi_dlg,0);
6339 dialog_running=false;
6340
6341 if(listening)
6342 music_stop();
6343
6344 if(do_pause_midi)
6345 {
6346 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6347 midi_suspended = midissuspRESUME;
6348 currmidi = restore_midi;
6349 midi_pos = paused_midi_pos;
6350 }
6351
6352 if(text) free(text);
6353 if(zmi) free(zmi);
6354 return D_O_K;
6355 }
6356
6357 int32_t onAbout()
6358 {
6359 char buf1[80]={0};
6360 std::ostringstream oss;
6361 sprintf(buf1,"ZQuest Classic Player");
6362 oss << buf1 << '\n';
6363 sprintf(buf1,"Version: %s", getVersionString());
6364 oss << buf1 << '\n';
6365 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6366 oss << buf1 << '\n';
6367
6368 InfoDialog("About ZC", oss.str()).show();
6369 return D_O_K;
6370 }
6371
6372 int32_t onQuest()
6373 {
6374 char fname[100];
6375 strcpy(fname, get_filename(qstpath));
6376 quest_dlg[0].dp2=get_zc_font(font_lfont);
6377 quest_dlg[1].dp = fname;
6378
6379 if(QHeader.quest_number==0)
6380 sprintf(str_a,"Custom");
6381 else
6382 sprintf(str_a,"%d",QHeader.quest_number);
6383
6384 sprintf(str_s,"%s",QHeader.getVerStr());
6385
6386 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6387 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6388
6389 large_dialog(quest_dlg);
6390
6391 do_zqdialog(quest_dlg, 0);
6392 return D_O_K;
6393 }
6394
6395 void call_vidmode_dlg();
6396 int32_t onVidMode()
6397 {
6398 call_vidmode_dlg();
6399 return D_O_K;
6400 }
6401
6402 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6403 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6404 //Added an extra statement, so that if the key is cleared to 0, the cleared
6405 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6406
6407 void load_ukeys(int32_t* arr)
6408 {
6409 arr[ukey_a] = Akey;
6410 arr[ukey_b] = Bkey;
6411 arr[ukey_s] = Skey;
6412 arr[ukey_l] = Lkey;
6413 arr[ukey_r] = Rkey;
6414 arr[ukey_p] = Pkey;
6415 arr[ukey_ex1] = Exkey1;
6416 arr[ukey_ex2] = Exkey2;
6417 arr[ukey_ex3] = Exkey3;
6418 arr[ukey_ex4] = Exkey4;
6419 arr[ukey_du] = DUkey;
6420 arr[ukey_dd] = DDkey;
6421 arr[ukey_dl] = DLkey;
6422 arr[ukey_dr] = DRkey;
6423 arr[ukey_mod1a] = cheat_modifier_keys[0];
6424 arr[ukey_mod1b] = cheat_modifier_keys[1];
6425 arr[ukey_mod2a] = cheat_modifier_keys[2];
6426 arr[ukey_mod2b] = cheat_modifier_keys[3];
6427 };
6428
6429 static const char* ukey_names[] = {
6430 "A", "B", "Start", "L", "R", "Map",
6431 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6432 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6433 "Cheat Mod R1", "Cheat Mod R2",
6434 };
6435 std::string get_ukey_name(int32_t k)
6436 {
6437 if (k < num_ukey) return ukey_names[k];
6438 return "";
6439 }
6440
6441 int32_t onKeyboard()
6442 {
6443 int32_t a = Akey;
6444 int32_t b = Bkey;
6445 int32_t s = Skey;
6446 int32_t l = Lkey;
6447 int32_t r = Rkey;
6448 int32_t p = Pkey;
6449 int32_t ex1 = Exkey1;
6450 int32_t ex2 = Exkey2;
6451 int32_t ex3 = Exkey3;
6452 int32_t ex4 = Exkey4;
6453 int32_t du = DUkey;
6454 int32_t dd = DDkey;
6455 int32_t dl = DLkey;
6456 int32_t dr = DRkey;
6457 int32_t mod1a = cheat_modifier_keys[0];
6458 int32_t mod1b = cheat_modifier_keys[1];
6459 int32_t mod2a = cheat_modifier_keys[2];
6460 int32_t mod2b = cheat_modifier_keys[3];
6461 bool done=false;
6462 int32_t ret;
6463
6464 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6465
6466 large_dialog(keyboard_control_dlg);
6467
6468 while(!done)
6469 {
6470 ret = do_zqdialog(keyboard_control_dlg,3);
6471
6472 if(ret==3) // OK
6473 {
6474 int32_t ukeys[num_ukey];
6475 load_ukeys(ukeys);
6476 std::vector<std::string> uniqueError;
6477 for(int32_t q = 0; q < num_ukey; ++q)
6478 {
6479 for(int32_t p = q+1; p < num_ukey; ++p)
6480 {
6481 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6482 {
6483 char buf[64];
6484 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6485 std::string str(buf);
6486 uniqueError.push_back(str);
6487 }
6488 }
6489 }
6490 if(uniqueError.size() == 0)
6491 {
6492 done = true;
6493 save_control_configs(true);
6494 }
6495 else
6496 {
6497 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6498 box_out("Cannot have duplicate keybinds!"); box_eol();
6499 for(std::vector<std::string>::iterator it = uniqueError.begin();
6500 it != uniqueError.end(); ++it)
6501 {
6502 box_out((*it).c_str()); box_eol();
6503 }
6504 box_end(true);
6505 }
6506 }
6507 else // Cancel
6508 {
6509 Akey = a;
6510 Bkey = b;
6511 Skey = s;
6512 Lkey = l;
6513 Rkey = r;
6514 Pkey = p;
6515 Exkey1 = ex1;
6516 Exkey2 = ex2;
6517 Exkey3 = ex3;
6518 Exkey4 = ex4;
6519 DUkey = du;
6520 DDkey = dd;
6521 DLkey = dl;
6522 DRkey = dr;
6523 cheat_modifier_keys[0] = mod1a;
6524 cheat_modifier_keys[1] = mod1b;
6525 cheat_modifier_keys[2] = mod2a;
6526 cheat_modifier_keys[3] = mod2b;
6527
6528 done=true;
6529 }
6530
6531 rest(1);
6532 }
6533
6534 return D_O_K;
6535 }
6536
6537 int32_t onGamepad()
6538 {
6539 if (al_get_num_joysticks() == 0)
6540 {
6541 InfoDialog("ZC", "No gamepads detected.").show();
6542 return D_O_K;
6543 }
6544
6545 int32_t a = Abtn;
6546 int32_t b = Bbtn;
6547 int32_t s = Sbtn;
6548 int32_t l = Lbtn;
6549 int32_t r = Rbtn;
6550 int32_t m = Mbtn;
6551 int32_t p = Pbtn;
6552 int32_t ex1 = Exbtn1;
6553 int32_t ex2 = Exbtn2;
6554 int32_t ex3 = Exbtn3;
6555 int32_t ex4 = Exbtn4;
6556 int32_t up = DUbtn;
6557 int32_t down = DDbtn;
6558 int32_t left = DLbtn;
6559 int32_t right = DRbtn;
6560 int32_t joy = joystick_index;
6561 int32_t stick_1 = js_stick_1_x_stick;
6562 int32_t stick_2 = js_stick_2_x_stick;
6563
6564 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6565 if(analog_movement)
6566 gamepad_dlg[56].flags|=D_SELECTED;
6567 else
6568 gamepad_dlg[56].flags&=~D_SELECTED;
6569
6570 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6571 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6572 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6573 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6574 // requires remapping every time.
6575 if (joystick_index >= al_get_num_joysticks())
6576 joystick_index = 0;
6577 gamepad_dlg[61].d2 = joystick_index;
6578
6579 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6580 if (!gamepad_dlg_cur_joystick)
6581 {
6582 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6583 return D_CLOSE;
6584 }
6585
6586 large_dialog(gamepad_dlg);
6587
6588 int32_t ret = do_zqdialog(gamepad_dlg,4);
6589
6590 if(ret == 4) //OK
6591 {
6592 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6593 joystick_index = gamepad_dlg[61].d2;
6594 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6595 if (!gamepad_dlg_cur_joystick)
6596 {
6597 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6598 return D_CLOSE;
6599 }
6600 js_stick_1_y_stick = js_stick_1_x_stick;
6601 js_stick_2_y_stick = js_stick_2_x_stick;
6602 save_control_configs(false);
6603 }
6604 else //Cancel
6605 {
6606 Abtn = a;
6607 Bbtn = b;
6608 Sbtn = s;
6609 Lbtn = l;
6610 Rbtn = r;
6611 Mbtn = m;
6612 Pbtn = p;
6613 Exbtn1 = ex1;
6614 Exbtn2 = ex2;
6615 Exbtn3 = ex3;
6616 Exbtn4 = ex4;
6617 DUbtn = up;
6618 DDbtn = down;
6619 DLbtn = left;
6620 DRbtn = right;
6621 joystick_index = joy;
6622 js_stick_1_x_stick = stick_1;
6623 js_stick_2_x_stick = stick_2;
6624 }
6625
6626 return D_O_K;
6627 }
6628
6629 int32_t onCheatKeys()
6630 {
6631 int32_t oldcheats[Cheat::Last][2];
6632 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6633
6634 bool done=false;
6635
6636 while(!done)
6637 {
6638 bool confirm = false;
6639 CheatKeysDialog(&confirm).show();
6640 if(confirm) // OK
6641 {
6642 std::vector<std::string> uniqueError;
6643 char buf[512];
6644 for(size_t q = 1; q < Cheat::Last; ++q)
6645 {
6646 if(cheatkeys[q][1] && !cheatkeys[q][0])
6647 {
6648 cheatkeys[q][0] = cheatkeys[q][1];
6649 cheatkeys[q][1] = 0;
6650 }
6651 }
6652 for(size_t q = 1; q < Cheat::Last; ++q)
6653 {
6654 if(!bindable_cheat((Cheat)q)) continue;
6655 for(size_t p = q+1; p < Cheat::Last; ++p)
6656 {
6657 if(!bindable_cheat((Cheat)p)) continue;
6658 for(size_t q2 = 0; q2 <= 1; ++q2)
6659 for(size_t p2 = 0; p2 <= 1; ++p2)
6660 {
6661 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6662 {
6663 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6664 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6665 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6666 get_keystr(cheatkeys[q][q2])));
6667 }
6668 }
6669 }
6670 }
6671 if(uniqueError.size() == 0)
6672 {
6673 done = true;
6674 save_cheatkeys();
6675 }
6676 else
6677 {
6678 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6679 box_out("Cannot have duplicate keybinds!"); box_eol();
6680 for(std::vector<std::string>::iterator it = uniqueError.begin();
6681 it != uniqueError.end(); ++it)
6682 {
6683 box_out((*it).c_str()); box_eol();
6684 }
6685 box_end(true);
6686 }
6687 }
6688 else // Cancel
6689 {
6690 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6691 done=true;
6692 }
6693 rest(1);
6694 }
6695
6696 return D_O_K;
6697 }
6698
6699 int32_t onSound()
6700 {
6701 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6702 {
6703 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6704 {
6705 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6706 }
6707 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6708 {
6709 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6710 }
6711 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6712 {
6713 emusic_volume = (int32_t)FFCore.usr_music_volume;
6714 }
6715 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6716 {
6717 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6718 }
6719 }
6720 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6721 {
6722 pan_style = (int32_t)FFCore.usr_panstyle;
6723 }
6724
6725 int32_t m = midi_volume;
6726 int32_t e = emusic_volume;
6727 int32_t s = sfx_volume;
6728 int32_t p = pan_style;
6729 pan_style = vbound(pan_style,0,3);
6730
6731 sound_dlg[0].dp2=get_zc_font(font_lfont);
6732
6733 large_dialog(sound_dlg);
6734
6735 midi_dp[1] = sound_dlg[6].x;
6736 midi_dp[2] = sound_dlg[6].y;
6737 emus_dp[1] = sound_dlg[8].x;
6738 emus_dp[2] = sound_dlg[8].y;
6739 sfx_dp[1] = sound_dlg[10].x;
6740 sfx_dp[2] = sound_dlg[10].y;
6741 pan_dp[1] = sound_dlg[11].x;
6742 pan_dp[2] = sound_dlg[11].y;
6743 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6744 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6745 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6746 sound_dlg[20].d2 = pan_style;
6747
6748 int32_t ret = do_zqdialog(sound_dlg,1);
6749
6750 if(ret==2)
6751 {
6752 master_volume(digi_volume,midi_volume);
6753 if (zcmusic)
6754 zcmusic_set_volume(zcmusic, emusic_volume);
6755
6756 int32_t temp_volume = sfx_volume;
6757 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6758 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6759 for(int32_t i=0; i<WAV_COUNT; ++i)
6760 {
6761 if(sfx_voice[i] >= 0)
6762 voice_set_volume(sfx_voice[i], temp_volume);
6763 }
6764 zc_set_config(sfx_sect,"midi",midi_volume);
6765 zc_set_config(sfx_sect,"sfx",sfx_volume);
6766 zc_set_config(sfx_sect,"emusic",emusic_volume);
6767 zc_set_config(sfx_sect,"pan",pan_style);
6768 }
6769 else
6770 {
6771 midi_volume = m;
6772 emusic_volume = e;
6773 sfx_volume = s;
6774 pan_style = p;
6775 }
6776
6777 return D_O_K;
6778 }
6779
6780 int32_t queding(char const* s1, char const* s2, char const* s3)
6781 {
6782 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6783 }
6784
6785 int32_t onQuit()
6786 {
6787 if(Playing)
6788 {
6789 int32_t ret=0;
6790
6791 if(get_qr(qr_NOCONTINUE))
6792 {
6793 if(standalone_mode)
6794 {
6795 ret=queding("End current game?",
6796 "The continue screen is disabled; the game",
6797 "will be reloaded from the last save.");
6798 }
6799 else
6800 {
6801 ret=queding("End current game?",
6802 "The continue screen is disabled. You will",
6803 "be returned to the file select screen.");
6804 }
6805 }
6806 else
6807 ret=queding("End current game?",NULL,NULL);
6808
6809 if(ret==1)
6810 {
6811 disableClickToFreeze=false;
6812 Quit=qQUIT;
6813
6814 // Trying to evade a door repair charge?
6815 if(repaircharge)
6816 {
6817 game->change_drupy(-repaircharge);
6818 repaircharge=0;
6819 }
6820
6821 return D_CLOSE;
6822 }
6823 }
6824
6825 return D_O_K;
6826 }
6827
6828 int32_t onTryQuitMenu()
6829 {
6830 return onTryQuit(true);
6831 }
6832
6833 int32_t onTryQuit(bool inMenu)
6834 {
6835 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6836 {
6837 if(active_cutscene.can_f6())
6838 {
6839 if(get_qr(qr_OLD_F6))
6840 {
6841 if(inMenu) onQuit();
6842 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6843 }
6844 else
6845 {
6846 disableClickToFreeze=false;
6847 GameFlags |= GAMEFLAG_TRYQUIT;
6848 }
6849 return D_CLOSE;
6850 }
6851 else active_cutscene.error();
6852 }
6853
6854 return D_O_K;
6855 }
6856
6857 int32_t onReset()
6858 {
6859 if(queding(" Reset system? ",NULL,NULL)==1)
6860 {
6861 disableClickToFreeze=false;
6862 Quit=qRESET;
6863 replay_quit();
6864 return D_CLOSE;
6865 }
6866
6867 return D_O_K;
6868 }
6869
6870 int32_t onExit()
6871 {
6872 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6873 {
6874 Quit=qEXIT;
6875 return D_CLOSE;
6876 }
6877
6878 return D_O_K;
6879 }
6880
6881 int32_t onDebug()
6882 {
6883 if(debug_enabled)
6884 set_debug(!get_debug());
6885 return D_O_K;
6886 }
6887
6888 int32_t onHeartBeep()
6889 {
6890 heart_beep=!heart_beep;
6891 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6892 return D_O_K;
6893 }
6894
6895 int32_t onSaveIndicator()
6896 {
6897 use_save_indicator = use_save_indicator ? 0 : 1;
6898 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6899 return D_O_K;
6900 }
6901
6902 int32_t onEpilepsy()
6903 {
6904 if(jwin_alert3(
6905 "Epilepsy Flash Reduction",
6906 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6907 "Disabling this will restore standard flash and wavy behaviour.",
6908 "Proceed?",
6909 "&Yes",
6910 "&No",
6911 NULL,
6912 'y',
6913 'n',
6914 0,
6915 get_zc_font(font_lfont)) == 1)
6916 {
6917 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6918 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6919 }
6920 return D_O_K;
6921 }
6922
6923 bool rc = false;
6924
6925 static DIALOG getnum_dlg[] =
6926 {
6927 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6928 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6929 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6930 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6931 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6932 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6933 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6934 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6935 };
6936
6937 int32_t getnumber(const char *prompt,int32_t initialval)
6938 {
6939 char buf[20];
6940 sprintf(buf,"%d",initialval);
6941 getnum_dlg[0].dp=(void *)prompt;
6942 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6943 getnum_dlg[2].dp=buf;
6944
6945 large_dialog(getnum_dlg);
6946
6947 if(do_zqdialog(getnum_dlg,2)==3)
6948 return atoi(buf);
6949
6950 return initialval;
6951 }
6952
6953 int32_t onLife()
6954 {
6955 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6956 cheats_enqueue(Cheat::Life, value);
6957 return D_O_K;
6958 }
6959
6960 int32_t onHeartC()
6961 {
6962 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6963 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6964 cheats_enqueue(Cheat::MaxLife, max_life);
6965 cheats_enqueue(Cheat::Life, life);
6966 return D_O_K;
6967 }
6968
6969 int32_t onMagicC()
6970 {
6971 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6972 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6973 cheats_enqueue(Cheat::MaxMagic, max_magic);
6974 cheats_enqueue(Cheat::Magic, magic);
6975 return D_O_K;
6976 }
6977
6978 int32_t onRupies()
6979 {
6980 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6981 cheats_enqueue(Cheat::Rupies, value);
6982 return D_O_K;
6983 }
6984
6985 int32_t onMaxBombs()
6986 {
6987 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6988 cheats_enqueue(Cheat::MaxBombs, value);
6989 cheats_enqueue(Cheat::Bombs, value);
6990 return D_O_K;
6991 }
6992
6993 int32_t onRefillLife()
6994 {
6995 cheats_enqueue(Cheat::Life, game->get_maxlife());
6996 return D_O_K;
6997 }
6998 int32_t onRefillMagic()
6999 {
7000 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
7001 return D_O_K;
7002 }
7003 int32_t onClock()
7004 {
7005 cheats_enqueue(Cheat::Clock);
7006 return D_O_K;
7007 }
7008
7009 int32_t onQstPath()
7010 {
7011 char initial_path[2048];
7012 chop_path(qstdir);
7013 strcpy(initial_path, qstdir);
7014
7015 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
7016 {
7017 char* path = result->data();
7018 chop_path(path);
7019 fix_filename_case(path);
7020 fix_filename_slashes(path);
7021 strcpy(qstdir,path);
7022 strcpy(qstpath,qstdir);
7023 zc_set_config("zeldadx","quest_dir",qstdir);
7024 flush_config_file();
7025 }
7026
7027 return D_O_K;
7028 }
7029
7030 #include "dialog/cheat_dialog.h"
7031 int32_t onCheat()
7032 {
7033 call_setcheat_dialog();
7034 game->set_cheat(maxcheat);
7035 if(cheat) game->did_cheat(true);
7036 return D_O_K;
7037 }
7038
7039 int32_t onCheatRupies()
7040 {
7041 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7042 return D_O_K;
7043 }
7044
7045 int32_t onCheatArrows()
7046 {
7047 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7048 return D_O_K;
7049 }
7050
7051 int32_t onCheatBombs()
7052 {
7053 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7054 return D_O_K;
7055 }
7056
7057 // *** screen saver
7058
7059 18522731 int32_t after_time()
7060 {
7061
1/2
✓ Branch 0 taken 18522731 times.
✗ Branch 1 not taken.
18522731 if(ss_enable == 0)
7062 return INT_MAX;
7063
7064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18522731 times.
18522731 if(ss_after <= 0)
7065 return 5 * 60;
7066
7067
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18522731 times.
18522731 if(ss_after <= 3)
7068 return ss_after * 15 * 60;
7069
7070
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18522731 times.
18522731 if(ss_after <= 13)
7071 return (ss_after - 3) * 60 * 60;
7072
7073 18522731 return MAX_IDLE + 1;
7074 18522731 }
7075
7076 static const char *after_str[15] =
7077 {
7078 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7079 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7080 "Never"
7081 };
7082
7083 const char *after_list(int32_t index, int32_t *list_size)
7084 {
7085 if(index < 0)
7086 {
7087 *list_size = 15;
7088 return NULL;
7089 }
7090
7091 return after_str[index];
7092 }
7093
7094 416 static ListData after__list(after_list, &font);
7095
7096 static DIALOG scrsaver_dlg[] =
7097 {
7098 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7099 416 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7100 416 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7101 416 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7102 416 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7103 416 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7104 416 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7105 416 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7106 416 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7107 416 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7108 416 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7109 416 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7110 416 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7111 416 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7112 };
7113
7114 int32_t onScreenSaver()
7115 {
7116 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7117 int32_t oldcfgs[3];
7118 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7119 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7120 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7121
7122 large_dialog(scrsaver_dlg);
7123
7124 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7125
7126 if(ret == 8 || ret == 9)
7127 {
7128 ss_after = scrsaver_dlg[5].d1;
7129 ss_speed = scrsaver_dlg[6].d2;
7130 ss_density = scrsaver_dlg[7].d2;
7131 if(oldcfgs[0] != ss_after)
7132 zc_set_config(cfg_sect,"ss_after",ss_after);
7133 if(oldcfgs[1] != ss_speed)
7134 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7135 if(oldcfgs[2] != ss_density)
7136 zc_set_config(cfg_sect,"ss_density",ss_density);
7137 }
7138
7139 if(ret == 9)
7140 // preview Screen Saver
7141 {
7142 clear_keybuf();
7143 Matrix(ss_speed, ss_density, 30);
7144 system_pal(true);
7145 sys_mouse();
7146 }
7147
7148 return D_O_K;
7149 }
7150
7151 /***** Menus *****/
7152
7153 enum
7154 {
7155 MENUID_GAME_LOADQUEST,
7156 MENUID_GAME_ENDGAME,
7157 };
7158
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu game_menu
7159 3328 {
7160
3/6
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
416 { "&Continue","ESC", onContinue },
7161
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
7162
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7163
3/6
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
416 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7164
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
7165 #ifdef __EMSCRIPTEN__
7166 { "&Reset","F7", onReset },
7167 #elif defined(ALLEGRO_MACOSX)
7168 { "&Reset","F7", onReset },
7169 { "&Quit","F8", onExit },
7170 #else
7171
3/6
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
416 { "&Reset","F9", onReset },
7172
3/6
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
416 { "&Quit","F10", onExit },
7173 #endif
7174 };
7175
7176
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu snapshot_format_menu
7177 2912 {
7178
4/8
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 416 times.
✗ Branch 7 not taken.
416 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7179
4/8
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 416 times.
✗ Branch 7 not taken.
416 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7180
4/8
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 416 times.
✗ Branch 7 not taken.
416 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7181
4/8
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 416 times.
✗ Branch 7 not taken.
416 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7182
4/8
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 416 times.
✗ Branch 7 not taken.
416 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7183
4/8
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 416 times.
✗ Branch 7 not taken.
416 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7184 };
7185
7186
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu bottom_8_pixels_menu
7187 1664 {
7188
4/8
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 416 times.
✗ Branch 7 not taken.
416 { "&Default (qst)", std::bind(onSetBottom8Pixels, 0) },
7189
4/8
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 416 times.
✗ Branch 7 not taken.
416 { "&On", std::bind(onSetBottom8Pixels, 1) },
7190
4/8
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 416 times.
✗ Branch 7 not taken.
416 { "&Off", std::bind(onSetBottom8Pixels, 2) },
7191 };
7192
7193
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu controls_menu
7194 1664 {
7195
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Key&board...", onKeyboard },
7196
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Gamepad...", onGamepad },
7197
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Cheat Keys...", onCheatKeys },
7198 };
7199
7200
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu name_entry_mode_menu
7201 1664 {
7202
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Keyboard", onKeyboardEntry },
7203
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Letter Grid", onLetterGridEntry },
7204
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Extended Letter Grid", onExtLetterGridEntry },
7205 };
7206
7207 static void set_controls_menu_active()
7208 {
7209
7210 }
7211
7212 enum
7213 {
7214 MENUID_WINDOW_LOCK_ASPECT,
7215 MENUID_WINDOW_LOCK_INTSCALE,
7216 MENUID_WINDOW_SAVE_SIZE,
7217 MENUID_WINDOW_SAVE_POS,
7218 MENUID_WINDOW_STRETCH,
7219 };
7220
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu window_menu
7221 2496 {
7222
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7223
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7224
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7225
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7226
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7227 };
7228 void call_zc_options_dlg();
7229 enum
7230 {
7231 MENUID_OPTIONS_PAUSE_BG,
7232 MENUID_OPTIONS_EPILEPSYPROT,
7233 MENUID_OPTIONS_SHOWBOTTOMPIXELS,
7234 };
7235
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu options_menu
7236 3328 {
7237
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Name &Entry Mode", &name_entry_mode_menu },
7238
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "S&napshot Format", &snapshot_format_menu },
7239
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Window Settings", &window_menu },
7240
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7241
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7242
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Show Bottom 8 Pixels", &bottom_8_pixels_menu, MENUID_OPTIONS_SHOWBOTTOMPIXELS },
7243
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "More Options", call_zc_options_dlg },
7244 };
7245 enum
7246 {
7247 MENUID_SETTINGS_CONTROLS,
7248 MENUID_SETTINGS_CAPFPS,
7249 MENUID_SETTINGS_SHOWFPS,
7250 MENUID_SETTINGS_SHOWTIME,
7251 MENUID_SETTINGS_CLICK_FREEZE,
7252 MENUID_SETTINGS_TRANSLAYERS,
7253 MENUID_SETTINGS_NESQUIT,
7254 MENUID_SETTINGS_VOLKEYS,
7255 MENUID_SETTINGS_HEARTBEEP,
7256 MENUID_SETTINGS_SAVEINDICATOR,
7257 MENUID_SETTINGS_DEBUG,
7258 };
7259
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu settings_menu
7260 7072 {
7261
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Sound...", onSound },
7262
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7263
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
7264
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Options", &options_menu },
7265
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
7266
3/6
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
416 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7267
3/6
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 416 times.
✗ Branch 5 not taken.
416 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7268
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7269
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7270
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7271
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7272
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7273
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7274
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7275
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
7276
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7277 };
7278
7279 enum
7280 {
7281 MENUID_MISC_FULLSCREEN,
7282 MENUID_MISC_VIDMODE,
7283 MENUID_MISC_QUEST_INFO,
7284 MENUID_MISC_QUEST_DIR,
7285 MENUID_MISC_CONSOLE,
7286 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7287 };
7288
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu misc_menu
7289 6240 {
7290
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&About...", onAbout },
7291 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7292 // { "&Credits...", onCredits },
7293
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7294
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7295
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
7296
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7297
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Quest &MIDI Info...", onMIDICredits },
7298
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7299
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
7300
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Take &Snapshot F12", onSnapshot },
7301
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Sc&reen Saver...", onScreenSaver },
7302
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Save ZC Configuration", OnSaveZCConfig },
7303
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7304
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7305
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Clear Directory Cache", OnnClearQuestDir },
7306 };
7307
7308 enum
7309 {
7310 MENUID_REFILL_ARROWS,
7311 };
7312
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu refill_menu
7313 2496 {
7314
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Life", onRefillLife },
7315
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Magic", onRefillMagic },
7316
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Bombs", onCheatBombs },
7317
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Rupees", onCheatRupies },
7318
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7319 };
7320
7321 enum
7322 {
7323 MENUID_SHOW_L0,
7324 MENUID_SHOW_L1,
7325 MENUID_SHOW_L2,
7326 MENUID_SHOW_L3,
7327 MENUID_SHOW_L4,
7328 MENUID_SHOW_L5,
7329 MENUID_SHOW_L6,
7330 MENUID_SHOW_OVER,
7331 MENUID_SHOW_PUSH,
7332 MENUID_SHOW_FFC,
7333 MENUID_SHOW_SPR,
7334 MENUID_SHOW_SCRIPTNAME,
7335 MENUID_SHOW_SOLIDITY,
7336 MENUID_SHOW_HITBOX,
7337 MENUID_SHOW_EFFECT,
7338 };
7339
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu show_menu
7340 7904 {
7341
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7342
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7343
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7344
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7345
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7346
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7347
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7348
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7349
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7350
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7351
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7352
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
7353
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7354
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 {},
7355
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7356
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7357
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7358
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Info Opacity", onShowInfoOpacity },
7359 };
7360
7361 enum
7362 {
7363 MENUID_CHEAT_CHOP_L1,
7364 MENUID_CHEAT_CHOP_L2,
7365 MENUID_CHEAT_CHOP_L3,
7366 MENUID_CHEAT_CHOP_L4,
7367 MENUID_CHEAT_INVULN,
7368 MENUID_CHEAT_NOCLIP,
7369 MENUID_CHEAT_IGNORESV,
7370 MENUID_CHEAT_GOFAST,
7371 };
7372
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 static NewMenu cheat_menu
7373 7072 {
7374
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Set &Cheat", onCheat },
7375
1/2
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
416 { MENUID_CHEAT_CHOP_L1 },
7376
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Re&fill", &refill_menu },
7377
1/2
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
416 { MENUID_CHEAT_CHOP_L2 },
7378
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7379
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Ma&x Bombs...", onMaxBombs },
7380
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Heart Containers...", onHeartC },
7381
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Magic Containers...", onMagicC },
7382
1/2
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
416 { MENUID_CHEAT_CHOP_L3 },
7383
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Hero Data...", onCheatConsole },
7384
1/2
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
416 { MENUID_CHEAT_CHOP_L4 },
7385
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7386
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7387
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7388
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Kill All Enemies", onKillCheat },
7389
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Trigger &Secrets", onSecretsCheat },
7390
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Trigger Secrets Perm", onSecretsCheatPerm },
7391
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Show/Hide Layer", &show_menu },
7392
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "Toggle &Light", onLightSwitch },
7393
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Goto Location...", onGoTo },
7394 };
7395
7396 #if DEVLEVEL > 0
7397 int32_t devLogging();
7398 int32_t devDebug();
7399 int32_t devTimestmp();
7400 #if DEVLEVEL > 1
7401 int32_t setCheat();
7402 #endif //DEVLEVEL > 1
7403 enum
7404 {
7405 MENUID_DEV_LOGGING,
7406 MENUID_DEV_DEBUG,
7407 MENUID_DEV_TIMESTAMP,
7408 MENUID_DEV_SETCHEAT,
7409 };
7410 static NewMenu dev_menu
7411 {
7412 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7413 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7414 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7415 #if DEVLEVEL > 1
7416 {},
7417 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7418 #endif //DEVLEVEL > 1
7419 };
7420 int32_t devLogging()
7421 {
7422 dev_logging = !dev_logging;
7423 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7424 return D_O_K;
7425 }
7426 // int32_t devDebug()
7427 // {
7428 // dev_debug = !dev_debug;
7429 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7430 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7431 // return D_O_K;
7432 // }
7433 int32_t devTimestmp()
7434 {
7435 dev_timestmp = !dev_timestmp;
7436 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7437 return D_O_K;
7438 }
7439 #if DEVLEVEL > 1
7440 int32_t setCheat()
7441 {
7442 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7443 return D_O_K;
7444 }
7445 #endif //DEVLEVEL > 1
7446 #endif //DEVLEVEL > 0
7447
7448 enum
7449 {
7450 MENUID_PLAYER_CHEAT,
7451 };
7452
1/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
416 TopMenu the_player_menu
7453 2496 {
7454
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Game", &game_menu },
7455
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Settings", &settings_menu },
7456
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7457
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&Replay", &replay_menu },
7458
2/4
✓ Branch 0 taken 416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 416 times.
✗ Branch 3 not taken.
416 { "&ZC", &misc_menu },
7459 #if DEVLEVEL > 0
7460 { "&Dev", &dev_menu },
7461 #endif
7462 };
7463
7464 int32_t onPauseInBackground()
7465 {
7466 if(jwin_alert3(
7467 "Toggle Pause In Background",
7468 "This action will change whether ZC Player pauses when the window loses focus.",
7469 "",
7470 "Proceed?",
7471 "&Yes",
7472 "&No",
7473 NULL,
7474 'y',
7475 'n',
7476 0,
7477 get_zc_font(font_lfont)) == 1)
7478 {
7479 pause_in_background = pause_in_background ? 0 : 1;
7480 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7481 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7482 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7483 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7484 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7485 }
7486 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7487 return D_O_K;
7488 }
7489
7490 int32_t onKeyboardEntry()
7491 {
7492 NameEntryMode=0;
7493 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7494 return D_O_K;
7495 }
7496
7497 int32_t onLetterGridEntry()
7498 {
7499 NameEntryMode=1;
7500 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7501 return D_O_K;
7502 }
7503
7504 int32_t onExtLetterGridEntry()
7505 {
7506 NameEntryMode=2;
7507 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7508 return D_O_K;
7509 }
7510
7511 static BITMAP* oldscreen;
7512 int32_t onFullscreenMenu()
7513 {
7514 PALETTE oldpal;
7515 get_palette(oldpal);
7516
7517 fullscreen = !fullscreen;
7518 all_toggle_fullscreen(fullscreen);
7519 zc_set_config("zeldadx","fullscreen",fullscreen);
7520
7521 zc_set_palette(oldpal);
7522 gui_mouse_focus=0;
7523 extern int32_t switch_type;
7524 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7525 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7526 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7527 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7528 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7529 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7530
7531 return D_O_K;
7532 }
7533
7534 314 void fix_menu()
7535 {
7536
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 314 times.
314 if(!debug_enabled)
7537 314 settings_menu.chop_index = 13;
7538 314 }
7539
7540 int32_t onSetSnapshotFormat(SnapshotType format)
7541 {
7542 SnapshotFormat = format;
7543 zc_set_config("zeldadx", "snapshot_format", format);
7544 snapshot_format_menu.select_only_index(format);
7545 return D_O_K;
7546 }
7547
7548 int32_t onSetBottom8Pixels(int option)
7549 {
7550 ShowBottomPixels = option;
7551 zc_set_config("zeldadx", "bottom_8_px", option);
7552 bottom_8_pixels_menu.select_only_index(option);
7553
7554 int qr = qr_HIDE_BOTTOM_8_PIXELS;
7555 bool value = false;
7556 if (option == 0)
7557 value = get_bit(quest_rules, qr) != 0; // This is the original value, as set in the qst file (or via scripting).
7558 else if (option == 1)
7559 value = false;
7560 else if (option == 2)
7561 value = true;
7562 enqueue_qr_change(qr, value);
7563
7564 return D_O_K;
7565 }
7566
7567 2919 void updateShowBottomPixels()
7568 {
7569 // It's too tricky the allow modifying the screen height between opening and closing the
7570 // active subscreen.
7571
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2893 times.
2919 if (subscreen_open)
7572 26 return;
7573
7574
1/2
✓ Branch 0 taken 2893 times.
✗ Branch 1 not taken.
2893 if (!GameLoaded)
7575 show_bottom_8px = false;
7576 else
7577 2893 show_bottom_8px = !get_qr(qr_HIDE_BOTTOM_8_PIXELS);
7578
7579 2893 int target_bitmap_height = show_bottom_8px ? 232 : 224;
7580
2/2
✓ Branch 0 taken 2787 times.
✓ Branch 1 taken 106 times.
2893 if (framebuf->h != target_bitmap_height)
7581 {
7582 106 BITMAP* new_framebuf = create_bitmap_ex(8, 256, target_bitmap_height);
7583 106 clear_bitmap(new_framebuf);
7584 106 blit(framebuf, new_framebuf, 0, 0, 0, 0, new_framebuf->w, new_framebuf->h);
7585
7586 106 destroy_bitmap(framebuf);
7587 106 destroy_bitmap(script_menu_buf);
7588 106 destroy_bitmap(f6_menu_buf);
7589 106 destroy_bitmap(darkscr_bmp);
7590 106 destroy_bitmap(darkscr_bmp_trans);
7591
7592 106 framebuf = new_framebuf;
7593 106 script_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7594 106 f6_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7595 106 darkscr_bmp = create_bitmap_ex(8, 256, target_bitmap_height);
7596 106 darkscr_bmp_trans = create_bitmap_ex(8, 256, target_bitmap_height);
7597
7598 106 rti_game.a4_bitmap = framebuf;
7599 106 rti_game.set_size(framebuf->w, framebuf->h);
7600 106 al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP);
7601 106 al_destroy_bitmap(rti_game.bitmap);
7602 106 rti_game.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7603 106 al_destroy_bitmap(rti_infolayer.bitmap);
7604 106 rti_infolayer.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7605 106 rti_infolayer.set_size(framebuf->w, framebuf->h);
7606 106 }
7607 2919 }
7608
7609 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7610 {
7611 PALETTE tmp;
7612
7613 for(int32_t i=0; i<256; i++)
7614 {
7615 tmp[i].r=r;
7616 tmp[i].g=g;
7617 tmp[i].b=b;
7618 }
7619
7620 fade_interpolate(src,tmp,dest,pos,from,to);
7621 }
7622
7623 46 void system_pal(bool force)
7624 {
7625
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46 if(is_sys_pal && !force) return;
7626 46 is_sys_pal = true;
7627 46 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7628 46 hw_palette = &syspal;
7629 46 update_hw_pal = true;
7630 46 }
7631
7632 static uint32_t entered_sys_pal = 0;
7633 46 void enter_sys_pal()
7634 {
7635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(is_sys_pal)
7636 {
7637 if(entered_sys_pal)
7638 ++entered_sys_pal;
7639 return;
7640 }
7641 46 sys_mouse();
7642 46 system_pal(true);
7643 46 ++entered_sys_pal;
7644 46 }
7645 46 void exit_sys_pal()
7646 {
7647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(entered_sys_pal)
7648 {
7649
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(!--entered_sys_pal)
7650 {
7651 46 game_pal();
7652 46 game_mouse();
7653 46 }
7654 46 }
7655 46 }
7656
7657 void switch_out_callback()
7658 {
7659 if (pause_in_background && !MenuOpen)
7660 {
7661 System();
7662 }
7663 }
7664
7665 void switch_in_callback()
7666 {
7667 }
7668
7669 1159 void game_pal()
7670 {
7671 1159 is_sys_pal = false;
7672 1159 entered_sys_pal = 0;
7673 1159 hw_palette = &RAMpal;
7674 1159 update_hw_pal = true;
7675 1159 }
7676
7677 static char bar_str[] = "";
7678
7679 46 void music_pause()
7680 {
7681 //al_pause_duh(tmplayer);
7682 46 zcmusic_pause(zcmusic, ZCM_PAUSE);
7683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(zcmixer->oldtrack)
7684 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7685 46 zc_midi_pause();
7686 46 }
7687
7688 void music_resume()
7689 {
7690 //al_resume_duh(tmplayer);
7691 zcmusic_pause(zcmusic, ZCM_RESUME);
7692 if (zcmixer->oldtrack)
7693 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7694 zc_midi_resume();
7695 }
7696
7697 7922 void music_stop()
7698 {
7699 //al_stop_duh(tmplayer);
7700 //unload_duh(tmusic);
7701 //tmusic=NULL;
7702 //tmplayer=NULL;
7703 7922 zcmusic_stop(zcmusic);
7704 7922 zcmusic_unload_file(zcmusic);
7705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7922 times.
7922 if (zcmixer->oldtrack)
7706 {
7707 zcmusic_stop(zcmixer->oldtrack);
7708 zcmusic_unload_file(zcmixer->oldtrack);
7709 }
7710 7922 zcmixer->newtrack = NULL;
7711 7922 zc_stop_midi();
7712 7922 currmidi=-1;
7713 7922 }
7714
7715 bool reload_fonts = false;
7716 void System()
7717 {
7718 mouse_down = gui_mouse_b();
7719 music_pause();
7720 pause_all_sfx();
7721 MenuOpen = true;
7722 enter_sys_pal();
7723 // FONT *oldfont=font;
7724 // font=tfont;
7725
7726 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7727 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7728
7729 #if DEVLEVEL > 1
7730 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7731 #endif
7732 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7733 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7734 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7735 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7736 clear_keybuf();
7737
7738 clear_bitmap(menu_bmp);
7739 oldscreen = screen;
7740 screen = menu_bmp;
7741
7742 the_player_menu.reset_state();
7743 the_player_menu.position(0, 0);
7744
7745 bool running = true;
7746 bool esc = key[KEY_ESC] || cMbtn();
7747 bool autopop = esc;
7748 do
7749 {
7750 if(reload_fonts)
7751 {
7752 init_custom_fonts();
7753 clear_bitmap(menu_bmp);
7754 broadcast_dialog_message(MSG_DRAW, 0);
7755 reload_fonts = false;
7756 }
7757 if(handle_close_btn_quit())
7758 break;
7759
7760 //update submenus
7761 {
7762 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7763 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7764 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7765 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7766 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7767 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7768 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7769 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7770
7771 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7772 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7773 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7774 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7775 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7776
7777 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7778 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7779 options_menu.disable_uid(MENUID_OPTIONS_SHOWBOTTOMPIXELS, replay_is_replaying());
7780
7781 name_entry_mode_menu.select_only_index(NameEntryMode);
7782
7783 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7784 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7785
7786 bool nocheat = (replay_is_replaying() || !Playing
7787 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7788 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7789 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7790 cheat_menu.chop_index.reset();
7791 if(cheat < 4)
7792 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7793 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7794 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, walk_through_walls);
7795 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7796 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7797
7798 show_menu.select_uid(MENUID_SHOW_L0, show_layers[0]);
7799 show_menu.select_uid(MENUID_SHOW_L1, show_layers[1]);
7800 show_menu.select_uid(MENUID_SHOW_L2, show_layers[2]);
7801 show_menu.select_uid(MENUID_SHOW_L3, show_layers[3]);
7802 show_menu.select_uid(MENUID_SHOW_L4, show_layers[4]);
7803 show_menu.select_uid(MENUID_SHOW_L5, show_layers[5]);
7804 show_menu.select_uid(MENUID_SHOW_L6, show_layers[6]);
7805 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7806 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7807 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7808 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7809 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7810 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7811 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7812 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7813
7814 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7815 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7816
7817 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7818 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7819
7820 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7821 #ifdef HAS_CURL
7822 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7823 #endif
7824 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7825 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7826 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7827
7828 snapshot_format_menu.select_only_index(SnapshotFormat);
7829 bottom_8_pixels_menu.select_only_index(ShowBottomPixels);
7830 }
7831
7832 if(debug_enabled)
7833 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7834
7835 if(autopop)
7836 clear_keybuf();
7837 the_player_menu.run(true);
7838 if(autopop)
7839 {
7840 the_player_menu.pop_sub(0, &the_player_menu);
7841 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7842 autopop = false;
7843 update_hw_screen();
7844 }
7845
7846 update_hw_screen();
7847
7848 auto mb = gui_mouse_b();
7849 if(XOR(mb, mouse_down))
7850 {
7851 if(!the_player_menu.has_mouse())
7852 if(mb)
7853 break;
7854 mouse_down = mb;
7855 }
7856
7857 if(input_idle(true) > after_time())
7858 // run Screeen Saver
7859 {
7860 // Screen saver enabled for now.
7861 clear_keybuf();
7862 Matrix(ss_speed, ss_density, 0);
7863 system_pal(true);
7864 sys_mouse();
7865 }
7866
7867 poll_keyboard();
7868 if(esc)
7869 {
7870 if(!key[KEY_ESC])
7871 esc = false;
7872 }
7873
7874 if(keypressed() && !CHECK_ALT) //System hotkeys
7875 {
7876 auto c = peekkey();
7877 bool eatkey = true;
7878 switch(c>>8)
7879 {
7880 //Spare keys used by the menu
7881 case KEY_UP:
7882 case KEY_DOWN:
7883 case KEY_LEFT:
7884 case KEY_RIGHT:
7885 eatkey = false;
7886 break;
7887 case KEY_F1:
7888 onThrottleFPS();
7889 break;
7890 case KEY_F2:
7891 onShowFPS();
7892 break;
7893 case KEY_F6:
7894 onTryQuitMenu();
7895 break;
7896 #ifndef ALLEGRO_MACOSX
7897 case KEY_F9:
7898 onReset();
7899 break;
7900 case KEY_F10:
7901 onExit();
7902 break;
7903 #else
7904 case KEY_F7:
7905 onReset();
7906 break;
7907 case KEY_F8:
7908 onExit();
7909 break;
7910 #endif
7911 case KEY_F12:
7912 onSnapshot();
7913 break;
7914 case KEY_TAB:
7915 onDebug();
7916 break;
7917 case KEY_ESC:
7918 if(!esc)
7919 running = false;
7920 break;
7921 }
7922 if(eatkey)
7923 readkey();
7924 }
7925 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7926 break;
7927 }
7928 while(running);
7929
7930 screen = oldscreen;
7931
7932 mouse_down=gui_mouse_b();
7933 MenuOpen = false;
7934 if(Quit)
7935 {
7936 kill_sfx();
7937 music_stop();
7938 update_hw_screen();
7939 }
7940 else
7941 {
7942 music_resume();
7943 resume_all_sfx();
7944
7945 if(rc)
7946 ringcolor(false);
7947 }
7948 exit_sys_pal();
7949
7950 eat_buttons();
7951
7952 rc=false;
7953 clear_keybuf();
7954
7955 zc_init_apply_cheat_delta();
7956 }
7957
7958 314 void fix_dialogs()
7959 {
7960 314 jwin_center_dialog(about_dlg);
7961 314 jwin_center_dialog(gamepad_dlg);
7962 314 jwin_center_dialog(credits_dlg);
7963 314 jwin_center_dialog(gamemode_dlg);
7964 314 jwin_center_dialog(getnum_dlg);
7965 314 jwin_center_dialog(goto_dlg);
7966 314 jwin_center_dialog(keyboard_control_dlg);
7967 314 jwin_center_dialog(midi_dlg);
7968 314 jwin_center_dialog(quest_dlg);
7969 314 jwin_center_dialog(scrsaver_dlg);
7970 314 jwin_center_dialog(sound_dlg);
7971 314 jwin_center_dialog(triforce_dlg);
7972 314 }
7973
7974 4330 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7975 {
7976
3/4
✓ Branch 0 taken 4330 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4308 times.
✓ Branch 3 taken 22 times.
4330 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7977 }
7978
7979 292 int32_t get_emusic_volume()
7980 {
7981 292 int32_t temp_volume = emusic_volume;
7982
2/4
✓ Branch 0 taken 292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 292 times.
✗ Branch 3 not taken.
292 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7983 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7984
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 292 times.
292 if (!zcmusic)
7985 292 return temp_volume;
7986 return (temp_volume * zcmusic->fadevolume) / 10000;
7987 292 }
7988
7989 int32_t get_zcmusicpos()
7990 {
7991 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7992 return debugtracething;
7993 return 0;
7994 }
7995
7996 void set_zcmusicpos(int32_t position)
7997 {
7998 zcmusic_set_curpos(zcmusic, position);
7999 }
8000
8001 void set_zcmusicspeed(int32_t speed)
8002 {
8003 zcmusic_set_speed(zcmusic, speed);
8004 }
8005
8006 int32_t get_zcmusiclen()
8007 {
8008 return zcmusic_get_length(zcmusic);
8009 }
8010
8011 3 void set_zcmusicloop(double start, double end)
8012 {
8013 3 zcmusic_set_loop(zcmusic, start, end);
8014 3 }
8015
8016 64164 void jukebox(int32_t index,int32_t loop)
8017 {
8018
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if (is_headless())
8019 64164 return;
8020
8021 music_stop();
8022
8023 if(index<0) index=MAXMIDIS-1;
8024
8025 if(index>=MAXMIDIS) index=0;
8026
8027 music_stop();
8028
8029 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8030 // stuck notes when a song stops. This fixes it.
8031 if(strcmp(midi_driver->name, "DIGMID")==0)
8032 zc_set_volume(0, 0);
8033
8034 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8035 zc_play_midi(tunes[index].data,loop);
8036
8037 if(tunes[index].start>0)
8038 zc_midi_seek(tunes[index].start);
8039
8040 midi_loop_start = tunes[index].loop_start;
8041 midi_loop_end = tunes[index].loop_end;
8042
8043 currmidi=index;
8044 master_volume(digi_volume, midi_volume);
8045 //midi_paused=false;
8046 64164 }
8047
8048 64164 void jukebox(int32_t index)
8049 {
8050
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index<0) index=MAXMIDIS-1;
8051
8052
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index>=MAXMIDIS) index=0;
8053
8054 // do nothing if it's already playing
8055
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64164 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64164 if(index==currmidi && midi_pos>=0)
8056 {
8057 return;
8058 }
8059
8060 64164 jukebox(index,tunes[index].loop);
8061 64164 }
8062
8063 102 void play_DmapMusic()
8064 {
8065
1/2
✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
102 if (is_headless())
8066 102 return;
8067
8068 static char tfile[2048];
8069 static int32_t ttrack=0;
8070 bool domidi=false;
8071
8072 int32_t fadeoutframes = 0;
8073 if (zcmusic != NULL)
8074 fadeoutframes = zcmusic->fadeoutframes;
8075
8076 if(DMaps[cur_dmap].tmusic[0]!=0)
8077 {
8078 if(zcmusic==NULL ||
8079 strcmp(zcmusic->filename,DMaps[cur_dmap].tmusic)!=0 ||
8080 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[cur_dmap].tmusictrack))
8081 {
8082 if (DMaps[cur_dmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8083 {
8084 if (play_enh_music_crossfade(DMaps[cur_dmap].tmusic, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes))
8085 {
8086 if (zcmusic != NULL)
8087 {
8088 zcmusic->fadeoutframes = DMaps[cur_dmap].tmusic_xfade_out;
8089 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8090 }
8091 }
8092 }
8093 else
8094 {
8095 if (zcmusic != NULL)
8096 {
8097 zcmusic_stop(zcmusic);
8098 zcmusic_unload_file(zcmusic);
8099 zcmusic = NULL;
8100 zcmixer->newtrack = NULL;
8101 }
8102
8103 zcmusic = zcmusic_load_for_quest(DMaps[cur_dmap].tmusic, qstpath).first;
8104 zcmixer->newtrack = zcmusic;
8105
8106 if (zcmusic != NULL)
8107 {
8108 zc_stop_midi();
8109 strcpy(tfile, DMaps[cur_dmap].tmusic);
8110 zcmusic_play(zcmusic, emusic_volume);
8111 int32_t temptracks = 0;
8112 temptracks = zcmusic_get_tracks(zcmusic);
8113 temptracks = (temptracks < 2) ? 1 : temptracks;
8114 ttrack = vbound(DMaps[cur_dmap].tmusictrack, 0, temptracks - 1);
8115 zcmusic_change_track(zcmusic, ttrack);
8116 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8117 }
8118 else
8119 {
8120 tfile[0] = 0;
8121 domidi = true;
8122 }
8123 }
8124 }
8125 }
8126 else
8127 {
8128 if (DMaps[cur_dmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[cur_dmap].tmusic) != 0)
8129 {
8130 play_enh_music_crossfade(NULL, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes);
8131 }
8132 else
8133 {
8134 domidi = true;
8135 }
8136 }
8137
8138 if(domidi)
8139 {
8140 int32_t m=DMaps[cur_dmap].midi;
8141
8142 switch(m)
8143 {
8144 case 1:
8145 jukebox(ZC_MIDI_OVERWORLD);
8146 break;
8147
8148 case 2:
8149 jukebox(ZC_MIDI_DUNGEON);
8150 break;
8151
8152 case 3:
8153 jukebox(ZC_MIDI_LEVEL9);
8154 break;
8155
8156 default:
8157 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8158 jukebox(m+MIDIOFFSET_DMAP);
8159 else
8160 music_stop();
8161 }
8162 }
8163 102 }
8164
8165 35715 void playLevelMusic()
8166 {
8167
1/2
✓ Branch 0 taken 35715 times.
✗ Branch 1 not taken.
35715 if (is_headless())
8168 35715 return;
8169
8170 int32_t m=hero_scr->screen_midi;
8171
8172 switch(m)
8173 {
8174 case -2:
8175 music_stop();
8176 break;
8177
8178 case -1:
8179 play_DmapMusic();
8180 break;
8181
8182 case 1:
8183 jukebox(ZC_MIDI_OVERWORLD);
8184 break;
8185
8186 case 2:
8187 jukebox(ZC_MIDI_DUNGEON);
8188 break;
8189
8190 case 3:
8191 jukebox(ZC_MIDI_LEVEL9);
8192 break;
8193
8194 default:
8195 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8196 jukebox(m+MIDIOFFSET_MAPSCR);
8197 else
8198 music_stop();
8199 }
8200 35715 }
8201
8202 4330 void master_volume(int32_t dv,int32_t mv)
8203 {
8204
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2322 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 355 times.
✓ Branch 4 taken 2322 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 355 times.
4330 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8205
8206
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2326 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 326 times.
✓ Branch 4 taken 2326 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 326 times.
4330 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8207
8208
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4330 times.
✓ Branch 2 taken 4330 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4330 times.
4330 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8209 4330 int32_t temp_vol = midi_volume;
8210
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 314 times.
4330 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8211 314 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8212 4330 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8213 4330 }
8214
8215 // array of voices, one for each sfx sample in the data file
8216 // 0+ = voice #
8217 // -1 = voice not allocated
8218 314 void Z_init_sound()
8219 {
8220
2/2
✓ Branch 0 taken 80384 times.
✓ Branch 1 taken 314 times.
80698 for(int32_t i=0; i<WAV_COUNT; i++)
8221 80384 sfx_voice[i]=-1;
8222
8223 314 const char* midis[ZC_MIDI_COUNT] = {
8224 "assets/dungeon.mid",
8225 "assets/ending.mid",
8226 "assets/gameover.mid",
8227 "assets/level9.mid",
8228 "assets/overworld.mid",
8229 "assets/title.mid",
8230 "assets/triforce.mid",
8231 };
8232
2/2
✓ Branch 0 taken 2198 times.
✓ Branch 1 taken 314 times.
2512 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8233 {
8234 2198 tunes[i].data = load_midi(midis[i]);
8235
1/2
✓ Branch 0 taken 2198 times.
✗ Branch 1 not taken.
2198 if (!tunes[i].data)
8236 Z_error_fatal("Missing required file %s\n", midis[i]);
8237 2198 }
8238
8239
2/2
✓ Branch 0 taken 79128 times.
✓ Branch 1 taken 314 times.
79442 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8240 79128 tunes[ZC_MIDI_COUNT+j].data=NULL;
8241
8242 314 master_volume(digi_volume,midi_volume);
8243 314 }
8244
8245 // returns number of voices currently allocated
8246 int32_t sfx_count()
8247 {
8248 int32_t c=0;
8249
8250 for(int32_t i=0; i<WAV_COUNT; i++)
8251 if(sfx_voice[i]!=-1)
8252 ++c;
8253
8254 return c;
8255 }
8256
8257 // clean up finished samples
8258 18314123 void sfx_cleanup()
8259 {
8260
2/2
✓ Branch 0 taken 4688415488 times.
✓ Branch 1 taken 18314123 times.
4706729611 for(int32_t i=0; i<WAV_COUNT; i++)
8261
3/4
✓ Branch 0 taken 1267317 times.
✓ Branch 1 taken 4687148171 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267317 times.
4689682805 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8262 {
8263 1267317 deallocate_voice(sfx_voice[i]);
8264 1267317 sfx_voice[i]=-1;
8265 1267317 }
8266 18314123 }
8267
8268 1267482 SAMPLE* sfx_get_sample(int32_t index)
8269 {
8270 // check index
8271
2/4
✓ Branch 0 taken 1267482 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267482 times.
1267482 if (index<=0 || index>=WAV_COUNT)
8272 return nullptr;
8273
8274
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 821235 times.
1267482 if (sfxdat)
8275 {
8276
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8277 {
8278 446247 return (SAMPLE*)sfxdata[index].dat;
8279 }
8280 else
8281 {
8282 return (SAMPLE*)sfxdata[Z35].dat;
8283 }
8284 }
8285 else
8286 {
8287 821235 return &customsfxdata[index];
8288 }
8289
8290 return nullptr;
8291 1267482 }
8292
8293 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8294 // if a voice is already allocated (and/or playing), then it just returns true
8295 // Returns true: voice is allocated
8296 // false: unsuccessful
8297 1880894 bool sfx_init(int32_t index)
8298 {
8299 // check index
8300
3/4
✓ Branch 0 taken 1400202 times.
✓ Branch 1 taken 480692 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1400202 times.
1880894 if(index<=0 || index>=WAV_COUNT)
8301 480692 return false;
8302
8303
2/2
✓ Branch 0 taken 132780 times.
✓ Branch 1 taken 1267422 times.
1400202 if (sfx_voice[index] == -1)
8304 {
8305 1267422 SAMPLE* sample = sfx_get_sample(index);
8306
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1267422 times.
1267422 if (!sample)
8307 return false;
8308
8309 1267422 sfx_voice[index] = allocate_voice(sample);
8310 1267422 }
8311
8312 1400202 return sfx_voice[index] != -1;
8313 1880894 }
8314
8315 int32_t sfx_get_default_freq(int32_t index)
8316 {
8317 if (sfxdat)
8318 {
8319 if (index < Z35)
8320 {
8321 return ((SAMPLE*)sfxdata[index].dat)->freq;
8322 }
8323 else
8324 {
8325 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8326 }
8327 }
8328 else
8329 {
8330 return customsfxdata[index].freq;
8331 }
8332 }
8333
8334 int32_t sfx_get_length(int32_t index)
8335 {
8336 if (sfxdat)
8337 {
8338 if (index < Z35)
8339 {
8340 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8341 }
8342 else
8343 {
8344 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8345 }
8346 }
8347 else
8348 {
8349 return int32_t(customsfxdata[index].len);
8350 }
8351 }
8352
8353 // plays an sfx sample
8354 1880894 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8355 {
8356
2/2
✓ Branch 0 taken 1400202 times.
✓ Branch 1 taken 480692 times.
1880894 if(!sfx_init(index))
8357 480692 return;
8358
1/2
✓ Branch 0 taken 1400202 times.
✗ Branch 1 not taken.
1400202 if (!is_headless())
8359 {
8360 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8361 voice_set_pan(sfx_voice[index], pan);
8362
8363 // Only used by ZScript currently
8364 if (freq <= -1)
8365 {
8366 freq = sfx_get_default_freq(index);
8367 }
8368 voice_set_frequency(sfx_voice[index], freq);
8369
8370 // Only used by ZScript currently
8371 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8372 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8373 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8374 voice_set_volume(sfx_voice[index], temp_volume);
8375
8376 int32_t pos = voice_get_position(sfx_voice[index]);
8377
8378 if (restart) voice_set_position(sfx_voice[index], 0);
8379
8380 if (pos <= 0)
8381 voice_start(sfx_voice[index]);
8382 }
8383
8384
3/4
✓ Branch 0 taken 865787 times.
✓ Branch 1 taken 534415 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 865787 times.
1400202 if (restart && replay_is_debug())
8385 {
8386 // TODO(replays): get rid of this bandaid next time replays are mass-updated.
8387 865787 const char* sfx_name = sfx_string[index];
8388
2/2
✓ Branch 0 taken 853987 times.
✓ Branch 1 taken 11800 times.
865787 if (strcmp(sfx_name, "Hero is hit") == 0)
8389 11800 sfx_name = "Player is hit";
8390
2/2
✓ Branch 0 taken 853860 times.
✓ Branch 1 taken 127 times.
853987 else if (strcmp(sfx_name, "Hero dies") == 0)
8391 127 sfx_name = "Player dies";
8392
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865787 times.
865787 replay_step_comment(fmt::format("sfx {}", sfx_name));
8393 865787 }
8394 1880894 }
8395
8396 // true if sfx is allocated
8397 203255 bool sfx_allocated(int32_t index)
8398 {
8399
3/4
✓ Branch 0 taken 33546 times.
✓ Branch 1 taken 169709 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33546 times.
203255 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8400 }
8401
8402 // start it (in loop mode) if it's not already playing,
8403 // otherwise adjust it to play in loop mode -DD
8404 118479 void cont_sfx(int32_t index)
8405 {
8406
1/2
✓ Branch 0 taken 118479 times.
✗ Branch 1 not taken.
118479 if (is_headless())
8407 118479 return;
8408
8409 if(!sfx_init(index))
8410 {
8411 return;
8412 }
8413
8414 if(voice_get_position(sfx_voice[index])<=0)
8415 {
8416 voice_set_position(sfx_voice[index],0);
8417 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8418 voice_set_volume(sfx_voice[index], sfx_volume);
8419 voice_start(sfx_voice[index]);
8420 }
8421 else
8422 {
8423 adjust_sfx(index, 128, true);
8424 }
8425 118479 }
8426
8427 // adjust parameters while playing
8428 4948 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8429 {
8430
4/6
✓ Branch 0 taken 4511 times.
✓ Branch 1 taken 437 times.
✓ Branch 2 taken 4511 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4511 times.
4948 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8431 4948 return;
8432
8433 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8434 voice_set_pan(sfx_voice[index],pan);
8435 4948 }
8436
8437 // pauses a voice
8438 3254 void pause_sfx(int32_t index)
8439 {
8440
3/6
✓ Branch 0 taken 3254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3254 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3254 times.
3254 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8441 voice_stop(sfx_voice[index]);
8442 3254 }
8443
8444 // resumes a voice
8445 1372 void resume_sfx(int32_t index)
8446 {
8447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1372 times.
1372 if (is_headless())
8448 1372 return;
8449
8450 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8451 voice_start(sfx_voice[index]);
8452 1372 }
8453
8454 // pauses all active voices
8455 1063 void pause_all_sfx()
8456 {
8457
2/2
✓ Branch 0 taken 272128 times.
✓ Branch 1 taken 1063 times.
273191 for(int32_t i=0; i<WAV_COUNT; i++)
8458
2/2
✓ Branch 0 taken 272126 times.
✓ Branch 1 taken 2 times.
272130 if(sfx_voice[i]!=-1)
8459 2 voice_stop(sfx_voice[i]);
8460 1063 }
8461
8462 // resumes all paused voices
8463 1017 void resume_all_sfx()
8464 {
8465
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8466
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8467 voice_start(sfx_voice[i]);
8468 1017 }
8469
8470 // stops an sfx and deallocates the voice
8471 14621773 void stop_sfx(int32_t index)
8472 {
8473
3/4
✓ Branch 0 taken 14374727 times.
✓ Branch 1 taken 247046 times.
✓ Branch 2 taken 14374727 times.
✗ Branch 3 not taken.
14621773 if(index<=0 || index>=WAV_COUNT)
8474 247046 return;
8475
8476
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 14374680 times.
14374727 if(sfx_voice[index]!=-1)
8477 {
8478 47 deallocate_voice(sfx_voice[index]);
8479 47 sfx_voice[index]=-1;
8480 47 }
8481 14621773 }
8482
8483 // Stops SFX played by Hero's item of the given family
8484 163371 void stop_item_sfx(int32_t family)
8485 {
8486 163371 int32_t id=current_item_id(family);
8487
8488
2/2
✓ Branch 0 taken 162269 times.
✓ Branch 1 taken 1102 times.
163371 if(id<0)
8489 162269 return;
8490
8491 1102 stop_sfx(itemsbuf[id].usesound);
8492 163371 }
8493
8494 9359 void kill_sfx()
8495 {
8496
2/2
✓ Branch 0 taken 2395904 times.
✓ Branch 1 taken 9359 times.
2405263 for(int32_t i=0; i<WAV_COUNT; i++)
8497
2/2
✓ Branch 0 taken 2395846 times.
✓ Branch 1 taken 58 times.
2395962 if(sfx_voice[i]!=-1)
8498 {
8499 58 deallocate_voice(sfx_voice[i]);
8500 58 sfx_voice[i]=-1;
8501 58 }
8502 9359 }
8503
8504 // TODO: when far out of bounds, sounds should dampen. currently we only pan.
8505 1201074 int32_t pan(int32_t x)
8506 {
8507
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1201074 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1201074 switch(pan_style)
8508 {
8509 // MONO
8510 case 0:
8511 return 128;
8512
8513 // 1/2
8514 case 1:
8515 1201074 x -= viewport.x;
8516 1201074 return vbound((x>>1)+68,0,255);
8517
8518 // 3/4
8519 case 2:
8520 x -= viewport.x;
8521 return vbound(((x*3)>>2)+36,0,255);
8522
8523 // FULL
8524 case 3:
8525 default:
8526 x -= viewport.x;
8527 return vbound(x,0,255);
8528 }
8529 1201074 }
8530
8531 50420172 bool joybtn(int32_t b)
8532 {
8533
1/2
✓ Branch 0 taken 50420172 times.
✗ Branch 1 not taken.
50420172 if(b == 0)
8534 return false;
8535
1/2
✓ Branch 0 taken 50420172 times.
✗ Branch 1 not taken.
50420172 if (b-1 >= joy[joystick_index].num_buttons)
8536 50420172 return false;
8537
8538 return joy[joystick_index].button[b-1].b !=0;
8539 50420172 }
8540
8541 bool joystick(int32_t s)
8542 {
8543 if(s < 0)
8544 return false;
8545 if (s >= joy[joystick_index].num_sticks)
8546 return false;
8547
8548 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8549 {
8550 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8551 return true;
8552 }
8553 return false;
8554 }
8555
8556 const char* joybtn_name(int32_t b)
8557 {
8558 if (b <= 0 || b > joy[joystick_index].num_buttons)
8559 return "";
8560
8561 return joy[joystick_index].button[b-1].name;
8562 }
8563
8564 const char* joystick_name(int32_t s)
8565 {
8566 if (s < 0 || s >= joy[joystick_index].num_sticks)
8567 return "";
8568
8569 return joy[joystick_index].stick[s].name;
8570 }
8571
8572 int32_t button_pressed()
8573 {
8574 if (joystick_index >= MAX_JOYSTICKS)
8575 return 0;
8576
8577 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8578 {
8579 if(joybtn(i))
8580 return i;
8581 }
8582
8583 return 0;
8584 }
8585
8586 int32_t next_press_key();
8587
8588 int32_t next_joy_input(bool buttons)
8589 {
8590 clear_keybuf();
8591
8592 //first, we need to wait until they're pressing no buttons
8593 for(;;)
8594 {
8595 if(keypressed())
8596 {
8597 switch(readkey()>>8)
8598 {
8599 case KEY_ESC:
8600 return -1;
8601
8602 case KEY_SPACE:
8603 return 0;
8604 }
8605 }
8606
8607 poll_joystick();
8608 bool done = true;
8609
8610 if (buttons)
8611 {
8612 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8613 {
8614 if(joybtn(i)) done = false;
8615 }
8616 }
8617 else
8618 {
8619 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8620 {
8621 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8622 return -2;
8623 }
8624 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8625 {
8626 if(joystick(i)) done = false;
8627 }
8628 }
8629
8630 if(done) break;
8631 rest(1);
8632 }
8633
8634 //now, we need to wait for them to press any button
8635 for(;;)
8636 {
8637 if(keypressed())
8638 {
8639 switch(readkey()>>8)
8640 {
8641 case KEY_ESC:
8642 return -1;
8643
8644 case KEY_SPACE:
8645 return 0;
8646 }
8647 }
8648
8649 poll_joystick();
8650
8651 if (buttons)
8652 {
8653 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8654 {
8655 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8656 return -2;
8657 }
8658 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8659 {
8660 if(joybtn(i))
8661 return i;
8662 }
8663 }
8664 else
8665 {
8666 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8667 {
8668 if(joystick(i))
8669 return i;
8670 }
8671 }
8672 rest(1);
8673 }
8674 }
8675
8676 7872867 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8677 {
8678
2/2
✓ Branch 0 taken 7843980 times.
✓ Branch 1 taken 28887 times.
7872867 bool ret = btn && !flag;
8679 7872867 flag = rawbtn;
8680
8681 7872867 return ret;
8682 }
8683 376964115 static bool rButton(bool &btn, bool &flag)
8684 {
8685
2/2
✓ Branch 0 taken 363046236 times.
✓ Branch 1 taken 13917879 times.
376964115 bool ret = btn && !flag;
8686 376964115 flag = btn;
8687
8688 376964115 return ret;
8689 }
8690 4643977 static bool rButtonPeek(bool btn, bool flag)
8691 {
8692
2/2
✓ Branch 0 taken 4296710 times.
✓ Branch 1 taken 347267 times.
4643977 if(!btn)
8693 {
8694 4296710 return false;
8695 }
8696
2/2
✓ Branch 0 taken 33615 times.
✓ Branch 1 taken 313652 times.
347267 else if(!flag)
8697 {
8698 33615 return true;
8699 }
8700
8701 313652 return false;
8702 4643977 }
8703
8704 // Updated only by keyboard/gamepad.
8705 // If in replay mode, this is set directly by the replay system.
8706 // This should never be read from directly - use control_state instead.
8707 bool raw_control_state[ZC_CONTROL_STATES];
8708
8709 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8710 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8711 // lasts until the next call to load_control_state.
8712 bool control_state[ZC_CONTROL_STATES];
8713 bool disable_control[ZC_CONTROL_STATES];
8714 bool drunk_toggle_state[11];
8715 bool disabledKeys[127];
8716 bool KeyInput[127];
8717 bool KeyPress[127];
8718
8719 bool key_current_frame[127];
8720 bool key_previous_frame[127];
8721
8722 static bool key_system[127];
8723 static bool key_system_previous[127];
8724 static bool key_system_press[127];
8725
8726 bool button_press[ZC_CONTROL_STATES];
8727 bool button_hold[ZC_CONTROL_STATES];
8728
8729 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8730 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8731 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8732 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8733 #define STICK_PRECISION 56 //define your own sensitivity
8734
8735 15667417 void load_control_state()
8736 {
8737 15667417 load_control_called_this_frame = true;
8738
8739
2/2
✓ Branch 0 taken 12464355 times.
✓ Branch 1 taken 3203062 times.
15667417 if (replay_version_check(8, 11))
8740 {
8741
2/2
✓ Branch 0 taken 57655116 times.
✓ Branch 1 taken 3203062 times.
60858178 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8742 57655116 down_control_states[i] = raw_control_state[i];
8743 3203062 }
8744
8745
2/2
✓ Branch 0 taken 15667396 times.
✓ Branch 1 taken 21 times.
15667417 if (!replay_is_replaying())
8746 {
8747
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8748
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8749
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8750
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8752
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8754
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8756
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8757
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8758
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8759
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8760
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8761
8762
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8763 {
8764 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8765 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8766 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8767 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8768 }
8769 else
8770 {
8771 21 raw_control_state[14] = false;
8772 21 raw_control_state[15] = false;
8773 21 raw_control_state[16] = false;
8774 21 raw_control_state[17] = false;
8775 }
8776 21 }
8777
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15667412 times.
15667417 if (replay_is_active())
8778 {
8779
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14455712 times.
15667412 if (replay_get_version() < 3)
8780 1211700 replay_poll();
8781
4/4
✓ Branch 0 taken 14455691 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12694316 times.
✓ Branch 3 taken 1761375 times.
14455712 else if (replay_is_replaying() && replay_get_version() < 6)
8782 1761375 replay_peek_input();
8783
4/4
✓ Branch 0 taken 12694316 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9491254 times.
✓ Branch 3 taken 3203062 times.
12694337 else if (replay_is_replaying() && replay_version_check(8, 11))
8784 3203062 replay_peek_input();
8785
2/2
✓ Branch 0 taken 14327470 times.
✓ Branch 1 taken 1339942 times.
15667412 if (replay_get_version() == 8)
8786 1339942 update_keys();
8787 15667412 }
8788
8789 // Some test replay files were made before a serious input bug was fixed, so instead
8790 // of re-doing them or tossing them out, just check for that zplay version.
8791
3/4
✓ Branch 0 taken 15667407 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15545507 times.
15667417 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8792
2/2
✓ Branch 0 taken 282013326 times.
✓ Branch 1 taken 15667407 times.
297680733 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8793 {
8794 282013326 control_state[i] = raw_control_state[i];
8795
4/4
✓ Branch 0 taken 53024004 times.
✓ Branch 1 taken 228989322 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412010 times.
282013326 if (botched_input && !control_state[i])
8796 50412010 down_control_states[i] = false;
8797 282013326 }
8798 15667407 bool did_bad_cutscene_btn = false;
8799
2/2
✓ Branch 0 taken 15667407 times.
✓ Branch 1 taken 282013326 times.
297680733 for(int q = 0; q < 18; ++q)
8800
4/4
✓ Branch 0 taken 13342550 times.
✓ Branch 1 taken 268670776 times.
✓ Branch 2 taken 13340839 times.
✓ Branch 3 taken 1711 times.
282015037 if(control_state[q] && !active_cutscene.can_button(q))
8801 {
8802 1711 control_state[q] = false;
8803 1711 did_bad_cutscene_btn = true;
8804 1711 }
8805
2/2
✓ Branch 0 taken 15666140 times.
✓ Branch 1 taken 1267 times.
15667407 if(did_bad_cutscene_btn)
8806 1267 active_cutscene.error();
8807
8808 15667407 button_press[0]=rButton(control_state[0],button_hold[0]);
8809 15667407 button_press[1]=rButton(control_state[1],button_hold[1]);
8810 15667407 button_press[2]=rButton(control_state[2],button_hold[2]);
8811 15667407 button_press[3]=rButton(control_state[3],button_hold[3]);
8812 15667407 button_press[4]=rButton(control_state[4],button_hold[4]);
8813 15667407 button_press[5]=rButton(control_state[5],button_hold[5]);
8814 15667407 button_press[6]=rButton(control_state[6],button_hold[6]);
8815 15667407 button_press[7]=rButton(control_state[7],button_hold[7]);
8816 15667407 button_press[8]=rButton(control_state[8],button_hold[8]);
8817 15667407 button_press[9]=rButton(control_state[9],button_hold[9]);
8818 15667407 button_press[10]=rButton(control_state[10],button_hold[10]);
8819 15667407 button_press[11]=rButton(control_state[11],button_hold[11]);
8820 15667407 button_press[12]=rButton(control_state[12],button_hold[12]);
8821 15667407 button_press[13]=rButton(control_state[13],button_hold[13]);
8822 15667407 button_press[14]=rButton(control_state[14],button_hold[14]);
8823 15667407 button_press[15]=rButton(control_state[15],button_hold[15]);
8824 15667407 button_press[16]=rButton(control_state[16],button_hold[16]);
8825 15667407 button_press[17]=rButton(control_state[17],button_hold[17]);
8826 15667407 }
8827
8828 // Returns true if any game key is pressed. This is needed because keypressed()
8829 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8830 78804933 bool zc_key_pressed()
8831 //may also need to use zc_getrawkey
8832 {
8833
7/10
✓ Branch 0 taken 63648174 times.
✓ Branch 1 taken 15156759 times.
✓ Branch 2 taken 15156759 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15156759 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12420819 times.
✓ Branch 7 taken 12420819 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4961269 times.
83766202 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8834
4/6
✓ Branch 0 taken 12420819 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12420819 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9456841 times.
✓ Branch 5 taken 9456841 times.
12420819 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8835
4/6
✓ Branch 0 taken 9456841 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9456841 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6258372 times.
✓ Branch 5 taken 6258372 times.
9456841 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8836
4/6
✓ Branch 0 taken 6258372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6258372 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5371041 times.
✓ Branch 5 taken 5371041 times.
6258372 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8837
1/2
✓ Branch 0 taken 5371041 times.
✗ Branch 1 not taken.
5371041 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8838
3/4
✓ Branch 0 taken 5183235 times.
✓ Branch 1 taken 187806 times.
✓ Branch 2 taken 5183235 times.
✗ Branch 3 not taken.
5371041 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8839
3/4
✓ Branch 0 taken 5036302 times.
✓ Branch 1 taken 146933 times.
✓ Branch 2 taken 5036302 times.
✗ Branch 3 not taken.
5183235 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8840
3/4
✓ Branch 0 taken 5014085 times.
✓ Branch 1 taken 22217 times.
✓ Branch 2 taken 5014085 times.
✗ Branch 3 not taken.
5036302 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8841
3/4
✓ Branch 0 taken 4987716 times.
✓ Branch 1 taken 26369 times.
✓ Branch 2 taken 4987716 times.
✗ Branch 3 not taken.
5014085 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8842
3/4
✓ Branch 0 taken 4980431 times.
✓ Branch 1 taken 7285 times.
✓ Branch 2 taken 4980431 times.
✗ Branch 3 not taken.
4987716 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8843
3/4
✓ Branch 0 taken 4963192 times.
✓ Branch 1 taken 17239 times.
✓ Branch 2 taken 4963192 times.
✗ Branch 3 not taken.
4980431 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8844
3/4
✓ Branch 0 taken 4961363 times.
✓ Branch 1 taken 1829 times.
✓ Branch 2 taken 4961363 times.
✗ Branch 3 not taken.
4963192 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8845
3/4
✓ Branch 0 taken 4961328 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4961328 times.
✗ Branch 3 not taken.
4961363 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8846
2/2
✓ Branch 0 taken 4961269 times.
✓ Branch 1 taken 59 times.
4961328 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8847 140857810 return true;
8848
8849 4961269 return false;
8850 18522731 }
8851
8852 300009727 bool getInput(int32_t btn, int input_flags)
8853 {
8854
3/4
✓ Branch 0 taken 267111969 times.
✓ Branch 1 taken 32897758 times.
✓ Branch 2 taken 267111969 times.
✗ Branch 3 not taken.
300009727 if((input_flags & INPUT_HERO_ACTION) && Hero.no_control())
8855 return false;
8856
8857 300009727 bool press = input_flags & INPUT_PRESS;
8858 300009727 bool drunk = input_flags & INPUT_DRUNK;
8859 300009727 bool ignoreDisable = input_flags & INPUT_IGNORE_DISABLE;
8860 300009727 bool eatEntirely = input_flags & INPUT_EAT_ENTIRELY;
8861 300009727 bool peek = input_flags & INPUT_PEEK;
8862
8863 300009727 bool ret = false, drunkstate = false, rawret = false;;
8864 300009727 bool* flag = &down_control_states[btn];
8865
2/7
✓ Branch 0 taken 281468089 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18541638 times.
300009727 switch(btn)
8866 {
8867 case btnF12:
8868 ret = zc_getkey(KEY_F12, ignoreDisable);
8869 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8870 eatEntirely = false;
8871 break;
8872 case btnF11:
8873 ret = zc_getkey(KEY_F11, ignoreDisable);
8874 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8875 eatEntirely = false;
8876 break;
8877 case btnF5:
8878 ret = zc_getkey(KEY_F5, ignoreDisable);
8879 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8880 eatEntirely = false;
8881 break;
8882 case btnQ:
8883 ret = zc_getkey(KEY_Q, ignoreDisable);
8884 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8885 eatEntirely = false;
8886 break;
8887 case btnI:
8888 ret = zc_getkey(KEY_I, ignoreDisable);
8889 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8890 eatEntirely = false;
8891 break;
8892 case btnM:
8893
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18541638 times.
18541638 if(FFCore.kb_typing_mode) return false;
8894 18541638 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8895 18541638 eatEntirely = false;
8896 18541638 break;
8897 default: //control_state[] index
8898
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 281468089 times.
281468089 if(FFCore.kb_typing_mode) return false;
8899
6/6
✓ Branch 0 taken 280088675 times.
✓ Branch 1 taken 1379414 times.
✓ Branch 2 taken 18130748 times.
✓ Branch 3 taken 261957927 times.
✓ Branch 4 taken 18127775 times.
✓ Branch 5 taken 2973 times.
281468089 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8900
2/2
✓ Branch 0 taken 15933189 times.
✓ Branch 1 taken 265531927 times.
281465116 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8901
4/4
✓ Branch 0 taken 250161422 times.
✓ Branch 1 taken 31306667 times.
✓ Branch 2 taken 7136 times.
✓ Branch 3 taken 31299531 times.
312774756 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8902 281468089 rawret = raw_control_state[btn];
8903 281468089 }
8904
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 300009727 times.
300009727 assert(flag);
8905
2/2
✓ Branch 0 taken 192542094 times.
✓ Branch 1 taken 107467633 times.
300009727 if(press)
8906 {
8907
2/2
✓ Branch 0 taken 4643977 times.
✓ Branch 1 taken 102823656 times.
107467633 if(peek)
8908 4643977 ret = rButtonPeek(ret, *flag);
8909
2/2
✓ Branch 0 taken 94950789 times.
✓ Branch 1 taken 7872867 times.
102823656 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8910 7872867 else ret = rButton(ret, *flag, rawret);
8911 107467633 }
8912
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 300009727 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
300009727 if(eatEntirely && ret) control_state[btn] = false;
8913
4/4
✓ Branch 0 taken 224513433 times.
✓ Branch 1 taken 75496294 times.
✓ Branch 2 taken 224513352 times.
✓ Branch 3 taken 81 times.
300009727 if(drunk && drunkstate) ret = !ret;
8914 300009727 return ret;
8915 300009727 }
8916
8917 15050021 byte getIntBtnInput(byte intbtn, int input_flags)
8918 {
8919 15050021 byte ret = 0;
8920
2/2
✓ Branch 0 taken 10628302 times.
✓ Branch 1 taken 4421719 times.
15050021 if(intbtn & INT_BTN_A) ret |= getInput(btnA, input_flags) ? INT_BTN_A : 0;
8921
2/2
✓ Branch 0 taken 14841055 times.
✓ Branch 1 taken 208966 times.
15050021 if(intbtn & INT_BTN_B) ret |= getInput(btnB, input_flags) ? INT_BTN_B : 0;
8922
2/2
✓ Branch 0 taken 14842373 times.
✓ Branch 1 taken 207648 times.
15050021 if(intbtn & INT_BTN_L) ret |= getInput(btnL, input_flags) ? INT_BTN_L : 0;
8923
2/2
✓ Branch 0 taken 14842373 times.
✓ Branch 1 taken 207648 times.
15050021 if(intbtn & INT_BTN_R) ret |= getInput(btnR, input_flags) ? INT_BTN_R : 0;
8924
2/2
✓ Branch 0 taken 14842373 times.
✓ Branch 1 taken 207648 times.
15050021 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, input_flags) ? INT_BTN_EX1 : 0;
8925
2/2
✓ Branch 0 taken 14842373 times.
✓ Branch 1 taken 207648 times.
15050021 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, input_flags) ? INT_BTN_EX2 : 0;
8926
2/2
✓ Branch 0 taken 14842373 times.
✓ Branch 1 taken 207648 times.
15050021 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, input_flags) ? INT_BTN_EX3 : 0;
8927
2/2
✓ Branch 0 taken 14842258 times.
✓ Branch 1 taken 207763 times.
15050021 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, input_flags) ? INT_BTN_EX4 : 0;
8928 15050021 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8929 }
8930
8931 7513 byte checkIntBtnVal(byte intbtn, byte vals)
8932 {
8933 7513 return intbtn&vals;
8934 }
8935
8936 208698 bool Up()
8937 {
8938 208698 return getInput(btnUp);
8939 }
8940 208697 bool Down()
8941 {
8942 208697 return getInput(btnDown);
8943 }
8944 208697 bool Left()
8945 {
8946 208697 return getInput(btnLeft);
8947 }
8948 208697 bool Right()
8949 {
8950 208697 return getInput(btnRight);
8951 }
8952 530261 bool cAbtn()
8953 {
8954 530261 return getInput(btnA);
8955 }
8956 3306494 bool cBbtn()
8957 {
8958 3306494 return getInput(btnB);
8959 }
8960 bool cSbtn()
8961 {
8962 return getInput(btnS);
8963 }
8964 208608 bool cLbtn()
8965 {
8966 208608 return getInput(btnL);
8967 }
8968 208608 bool cRbtn()
8969 {
8970 208608 return getInput(btnR);
8971 }
8972 bool cPbtn()
8973 {
8974 return getInput(btnP);
8975 }
8976 bool cEx1btn()
8977 {
8978 return getInput(btnEx1);
8979 }
8980 bool cEx2btn()
8981 {
8982 return getInput(btnEx2);
8983 }
8984 bool cEx3btn()
8985 {
8986 return getInput(btnEx3);
8987 }
8988 bool cEx4btn()
8989 {
8990 return getInput(btnEx4);
8991 }
8992 bool AxisUp()
8993 {
8994 return getInput(btnAxisUp);
8995 }
8996 bool AxisDown()
8997 {
8998 return getInput(btnAxisDown);
8999 }
9000 bool AxisLeft()
9001 {
9002 return getInput(btnAxisLeft);
9003 }
9004 bool AxisRight()
9005 {
9006 return getInput(btnAxisRight);
9007 }
9008
9009 bool cMbtn()
9010 {
9011 return getInput(btnM);
9012 }
9013 bool cF12()
9014 {
9015 return getInput(btnF12);
9016 }
9017 bool cF11()
9018 {
9019 return getInput(btnF11);
9020 }
9021 bool cF5()
9022 {
9023 return getInput(btnF5);
9024 }
9025 bool cQ()
9026 {
9027 return getInput(btnQ);
9028 }
9029 bool cI()
9030 {
9031 return getInput(btnI);
9032 }
9033
9034 211312 bool rUp()
9035 {
9036 211312 return getInput(btnUp, INPUT_PRESS);
9037 }
9038 211099 bool rDown()
9039 {
9040 211099 return getInput(btnDown, INPUT_PRESS);
9041 }
9042 210903 bool rLeft()
9043 {
9044 210903 return getInput(btnLeft, INPUT_PRESS);
9045 }
9046 210163 bool rRight()
9047 {
9048 210163 return getInput(btnRight, INPUT_PRESS);
9049 }
9050 4648 bool rAbtn()
9051 {
9052 4648 return getInput(btnA, INPUT_PRESS);
9053 }
9054 bool rBbtn()
9055 {
9056 return getInput(btnB, INPUT_PRESS);
9057 }
9058 210364 bool rSbtn()
9059 {
9060 210364 return getInput(btnS, INPUT_PRESS);
9061 }
9062 18522731 bool rMbtn()
9063 {
9064 18522731 return getInput(btnM, INPUT_PRESS);
9065 }
9066 186046 bool rLbtn()
9067 {
9068 186046 return getInput(btnL, INPUT_PRESS);
9069 }
9070 186041 bool rRbtn()
9071 {
9072 186041 return getInput(btnR, INPUT_PRESS);
9073 }
9074 208608 bool rPbtn()
9075 {
9076 208608 return getInput(btnP, INPUT_PRESS);
9077 }
9078 bool rEx1btn()
9079 {
9080 return getInput(btnEx1, INPUT_PRESS);
9081 }
9082 bool rEx2btn()
9083 {
9084 return getInput(btnEx2, INPUT_PRESS);
9085 }
9086 186037 bool rEx3btn()
9087 {
9088 186037 return getInput(btnEx3, INPUT_PRESS);
9089 }
9090 186037 bool rEx4btn()
9091 {
9092 186037 return getInput(btnEx4, INPUT_PRESS);
9093 }
9094 bool rAxisUp()
9095 {
9096 return getInput(btnAxisUp, INPUT_PRESS);
9097 }
9098 bool rAxisDown()
9099 {
9100 return getInput(btnAxisDown, INPUT_PRESS);
9101 }
9102 bool rAxisLeft()
9103 {
9104 return getInput(btnAxisLeft, INPUT_PRESS);
9105 }
9106 bool rAxisRight()
9107 {
9108 return getInput(btnAxisRight, INPUT_PRESS);
9109 }
9110
9111 bool rF11()
9112 {
9113 return getInput(btnF11, INPUT_PRESS);
9114 }
9115 bool rQ()
9116 {
9117 return getInput(btnQ, INPUT_PRESS);
9118 }
9119 bool rI()
9120 {
9121 return getInput(btnI, INPUT_PRESS);
9122 }
9123
9124 bool DrunkUp()
9125 {
9126 return getInput(btnUp, INPUT_DRUNK);
9127 }
9128 bool DrunkDown()
9129 {
9130 return getInput(btnDown, INPUT_DRUNK);
9131 }
9132 bool DrunkLeft()
9133 {
9134 return getInput(btnLeft, INPUT_DRUNK);
9135 }
9136 bool DrunkRight()
9137 {
9138 return getInput(btnRight, INPUT_DRUNK);
9139 }
9140 bool DrunkcAbtn()
9141 {
9142 return getInput(btnA, INPUT_DRUNK);
9143 }
9144 bool DrunkcBbtn()
9145 {
9146 return getInput(btnB, INPUT_DRUNK);
9147 }
9148 bool DrunkcEx1btn()
9149 {
9150 return getInput(btnEx1, INPUT_DRUNK);
9151 }
9152 bool DrunkcEx2btn()
9153 {
9154 return getInput(btnEx2, INPUT_DRUNK);
9155 }
9156 bool DrunkcSbtn()
9157 {
9158 return getInput(btnS, INPUT_DRUNK);
9159 }
9160 bool DrunkcMbtn()
9161 {
9162 return getInput(btnM, INPUT_DRUNK);
9163 }
9164 bool DrunkcLbtn()
9165 {
9166 return getInput(btnL, INPUT_DRUNK);
9167 }
9168 bool DrunkcRbtn()
9169 {
9170 return getInput(btnR, INPUT_DRUNK);
9171 }
9172 bool DrunkcPbtn()
9173 {
9174 return getInput(btnP, INPUT_DRUNK);
9175 }
9176
9177 bool DrunkrUp()
9178 {
9179 return getInput(btnUp, INPUT_PRESS | INPUT_DRUNK);
9180 }
9181 bool DrunkrDown()
9182 {
9183 return getInput(btnDown, INPUT_PRESS | INPUT_DRUNK);
9184 }
9185 bool DrunkrLeft()
9186 {
9187 return getInput(btnLeft, INPUT_PRESS | INPUT_DRUNK);
9188 }
9189 bool DrunkrRight()
9190 {
9191 return getInput(btnRight, INPUT_PRESS | INPUT_DRUNK);
9192 }
9193 bool DrunkrAbtn()
9194 {
9195 return getInput(btnA, INPUT_PRESS | INPUT_DRUNK);
9196 }
9197 bool DrunkrBbtn()
9198 {
9199 return getInput(btnB, INPUT_PRESS | INPUT_DRUNK);
9200 }
9201 bool DrunkrEx1btn()
9202 {
9203 return getInput(btnEx1, INPUT_PRESS | INPUT_DRUNK);
9204 }
9205 bool DrunkrEx2btn()
9206 {
9207 return getInput(btnEx2, INPUT_PRESS | INPUT_DRUNK);
9208 }
9209 bool DrunkrEx3btn()
9210 {
9211 return getInput(btnEx3, INPUT_PRESS | INPUT_DRUNK);
9212 }
9213 bool DrunkrEx4btn()
9214 {
9215 return getInput(btnEx4, INPUT_PRESS | INPUT_DRUNK);
9216 }
9217 bool DrunkrSbtn()
9218 {
9219 return getInput(btnS, INPUT_PRESS | INPUT_DRUNK);
9220 }
9221 bool DrunkrMbtn()
9222 {
9223 return getInput(btnM, INPUT_PRESS | INPUT_DRUNK);
9224 }
9225 bool DrunkrLbtn()
9226 {
9227 return getInput(btnL, INPUT_PRESS | INPUT_DRUNK);
9228 }
9229 bool DrunkrRbtn()
9230 {
9231 return getInput(btnR, INPUT_PRESS | INPUT_DRUNK);
9232 }
9233 bool DrunkrPbtn()
9234 {
9235 return getInput(btnP, INPUT_PRESS | INPUT_DRUNK);
9236 }
9237
9238 18907 void eat_buttons()
9239 {
9240 18907 getInput(btnA, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9241 18907 getInput(btnB, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9242 18907 getInput(btnS, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9243 18907 getInput(btnM, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9244 18907 getInput(btnL, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9245 18907 getInput(btnR, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9246 18907 getInput(btnP, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9247 18907 getInput(btnEx1, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9248 18907 getInput(btnEx2, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9249 18907 getInput(btnEx3, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9250 18907 getInput(btnEx4, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9251 18907 }
9252
9253 // Is true for the _first frame_ of a key press.
9254 // But! it is possible that a script manually sets the value of KeyPress,
9255 // in which case it will be restored to the "true" value based on `key_current_frame`
9256 // and `key_previous_frame` on the next frame.
9257 46 bool zc_readkey(int32_t k, bool ignoreDisable)
9258 {
9259
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(ignoreDisable) return KeyPress[k];
9260
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 switch(k)
9261 {
9262 case KEY_F7:
9263 case KEY_F8:
9264 case KEY_F9:
9265 return KeyPress[k];
9266
9267 default:
9268
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 return KeyPress[k] && !disabledKeys[k];
9269 }
9270 46 }
9271
9272 // Is true for _every frame_ a key is held down.
9273 // But! it is possible that a script manually sets the value of KeyInput,
9274 // in which case it will be restored to the "true" value based on `key_current_frame`
9275 // on the next frame.
9276 bool zc_getkey(int32_t k, bool ignoreDisable)
9277 {
9278 if(ignoreDisable) return KeyInput[k];
9279 switch(k)
9280 {
9281 case KEY_F7:
9282 case KEY_F8:
9283 case KEY_F9:
9284 return KeyInput[k];
9285
9286 default:
9287 return KeyInput[k] && !disabledKeys[k];
9288 }
9289 }
9290
9291 // Reads (and then clears) the current frame key state directly.
9292 // Scripts can also modify `key_current_frame`.
9293 900 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9294 {
9295
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 898 times.
900 if(zc_getrawkey(k, ignoreDisable))
9296 {
9297 2 _key[k]=key[k]=key_current_frame[k]=0;
9298 2 return true;
9299 }
9300 898 _key[k]=key[k]=key_current_frame[k]=0;
9301 898 return false;
9302 900 }
9303
9304 // Reads the current frame key state directly.
9305 // Scripts can also modify `key_current_frame`.
9306 125817047 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9307 {
9308
2/2
✓ Branch 0 taken 107294224 times.
✓ Branch 1 taken 18522823 times.
125817047 if(ignoreDisable) return key_current_frame[k];
9309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18522823 times.
18522823 switch(k)
9310 {
9311 case KEY_F7:
9312 case KEY_F8:
9313 case KEY_F9:
9314 return key_current_frame[k];
9315
9316 default:
9317
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18522823 times.
18522823 return key_current_frame[k] && !disabledKeys[k];
9318 }
9319 125817047 }
9320
9321 // Only used for a handful of keys, like tilde and Function keys.
9322 // This state is never read within the game.
9323 // It exists so that all keyboard input still functions during replay,
9324 // without inadvertently doing things like toggling throttling if the player
9325 // presses ~
9326 bool zc_get_system_key(int32_t k)
9327 {
9328 return key_system[k];
9329 }
9330
9331 // True for the _first_ frame of a key press.
9332 166704579 bool zc_read_system_key(int32_t k)
9333 {
9334 166704579 return key_system_press[k];
9335 }
9336
9337 2352386837 bool is_system_key(int32_t k)
9338 {
9339
2/2
✓ Branch 0 taken 2185682258 times.
✓ Branch 1 taken 166704579 times.
2352386837 switch (k)
9340 {
9341 case KEY_BACKQUOTE:
9342 case KEY_CLOSEBRACE:
9343 case KEY_END:
9344 case KEY_HOME:
9345 case KEY_OPENBRACE:
9346 case KEY_PGDN:
9347 case KEY_PGUP:
9348 case KEY_TAB:
9349 case KEY_TILDE:
9350 166704579 return true;
9351 }
9352 2185682258 return is_Fkey(k);
9353 2352386837 }
9354
9355 18522731 void update_system_keys()
9356 {
9357
2/2
✓ Branch 0 taken 2352386837 times.
✓ Branch 1 taken 18522731 times.
2370909568 for (int32_t q = 0; q < 127; ++q)
9358 {
9359
2/2
✓ Branch 0 taken 388977351 times.
✓ Branch 1 taken 1963409486 times.
2352386837 if (!is_system_key(q))
9360 1963409486 continue;
9361
9362 388977351 key_system[q] = key[q];
9363
1/2
✓ Branch 0 taken 388977351 times.
✗ Branch 1 not taken.
388977351 key_system_press[q] = key_system[q] && !key_system_previous[q];
9364 388977351 key_system_previous[q] = key_system[q];
9365 388977351 }
9366 18522731 }
9367
9368 19862673 void update_keys()
9369 {
9370
2/2
✓ Branch 0 taken 2522559471 times.
✓ Branch 1 taken 19862673 times.
2542422144 for (int32_t q = 0; q < 127; ++q)
9371 {
9372 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9373
2/2
✓ Branch 0 taken 2522546771 times.
✓ Branch 1 taken 12700 times.
2522559471 if (!replay_is_replaying())
9374 12700 key_current_frame[q] = key[q];
9375
9376
2/2
✓ Branch 0 taken 2503172928 times.
✓ Branch 1 taken 19386543 times.
2522559471 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9377 2522559471 KeyInput[q] = key_current_frame[q];
9378 2522559471 key_previous_frame[q] = key_current_frame[q];
9379 2522559471 }
9380 19862673 }
9381
9382